import re


def satisfy_label_requirements(k, v):
  """Takes in a key and value and returns (String, String) that satisfies the label text requirements.

  Label text requirements include max length of 63 chars, only allowing (a-z, 0-9, -, _),
  key must start with a letter, and value must be a string.
  https://cloud.google.com/deployment-manager/docs/creating-managing-labels#requirements

  Arguments:
    k: stringify-able input
    v: stringify-able input

  Returns:
    (String, String) that satisfies the label text requirements for key and value
  """

  LABEL_MAX_LENGTH = 63
  ALLOWED_CHARS_COMPLEMENT = r'[^a-z0-9-_]+'
  KEY_ALLOWED_STARTING_CHARS_COMPLEMENT = r'^[^a-z]*'

  new_k = str(k).lower()
  new_k = re.sub(KEY_ALLOWED_STARTING_CHARS_COMPLEMENT, '', new_k) # make sure first char of key is a lowercase letter
  new_k = re.sub(ALLOWED_CHARS_COMPLEMENT, '--', new_k) # remove each group of illegal characters and replace with '--'
  new_k = new_k[0:LABEL_MAX_LENGTH]

  new_v = str(v).lower()
  new_v = re.sub(ALLOWED_CHARS_COMPLEMENT, '--', new_v) # remove each group of illegal characters and replace with '--'
  new_v = new_v[0:LABEL_MAX_LENGTH]

  return new_k, new_v