Given a time in the format of hh:mm (12-hour format) 0 < HH < 12, 0 <= MM < 60. The task is to convert it into words.
Note: There are different corner cases appears for simplicity refer this example:
6:00 six o'clock
6:10 ten minutes past six
6:15 quarter past six
6:30 half past six
6:45 quarter to seven
6:47 thirteen minutes to seven
Example 1:
Input: H = 6, M = 0
Output: six o' clock
Explanation: 6H:0M = six o' clock.
Example 2:
Input: N = 6, M = 10
Output: ten minutes past six
Explanation: 6H:10M = ten minutes past six.
Your Task:  
You dont need to read input or print anything. Complete the function timeToWord() which takes H and M as input parameter and returns words converted from given time.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(k^{2})
Constraints:
0 < H < 12
0= < M < 60

Difficulty: EASY
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(k^{2})

Starter code:
#User function Template for python3

class Solution:

	def timeToWord(self, H, M):

		# code here



Solutions:
class Solution:

	def timeToWord(self, H, M):
		nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']
		if M == 0:
			return ''.join(map(str, (nums[H], " o' clock")))
		elif M == 1:
			return ' '.join(map(str, ('one minute past', nums[H])))
		elif M == 59:
			return ' '.join(map(str, ('one minute to', nums[H % 12 + 1])))
		elif M == 15:
			return ' '.join(map(str, ('quarter past', nums[H])))
		elif M == 30:
			return ' '.join(map(str, ('half past', nums[H])))
		elif M == 45:
			return ' '.join(map(str, ('quarter to', nums[H % 12 + 1])))
		elif M < 30:
			return ' '.join(map(str, (nums[M], 'minutes past', nums[H])))
		elif M > 30:
			return ' '.join(map(str, (nums[60 - M], 'minutes to', nums[H % 12 + 1])))


class Solution:

	def timeToWord(self, hour, minutes):
		nums = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']
		if minutes == 0:
			return nums[hour - 1] + " o'clock"
		elif minutes == 15:
			return 'quarter past ' + nums[hour - 1]
		elif minutes == 30:
			return 'half past ' + nums[hour - 1]
		elif minutes == 45:
			if hour < 12:
				return 'quarter to ' + nums[hour]
			else:
				return 'quarter to one'
		elif minutes <= 20:
			if minutes != 1:
				return nums[minutes - 1] + ' minutes past ' + nums[hour - 1]
			else:
				return nums[minutes - 1] + ' minute past ' + nums[hour - 1]
		elif 20 < minutes < 30:
			return 'twenty ' + nums[minutes - 20 - 1] + ' minutes past ' + nums[hour - 1]
		elif 30 < minutes < 40:
			if hour < 12:
				return 'twenty ' + nums[40 - minutes - 1] + ' minutes to ' + nums[hour]
			else:
				return 'twenty ' + nums[40 - minutes - 1] + ' minutes to one'
		elif hour < 12:
			if minutes != 59:
				return nums[60 - minutes - 1] + ' minutes to ' + nums[hour]
			else:
				return nums[60 - minutes - 1] + ' minute to ' + nums[hour]
		elif minutes != 59:
			return nums[60 - minutes - 1] + ' minutes to one'
		else:
			return nums[60 - minutes - 1] + ' minute to one'


class Solution:

	def timeToWord(self, H, M):
		min = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']
		hours = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'one']
		min_str = ''
		if M > 1:
			minstr2 = 'minutes'
		else:
			minstr2 = 'minute'
		if M > 30 and M < 60 and (M % 15 != 0):
			minutes = 60 - M
			if minutes > 1:
				minstr2 = 'minutes'
			else:
				minstr2 = 'minute'
			min_str = min[60 - M] + ' ' + minstr2 + ' to ' + hours[H + 1]
		elif M > 0 and M < 30 and (M % 15 != 0):
			min_str = min[M] + ' ' + minstr2 + ' past ' + hours[H]
		elif M > 0 and M <= 30:
			if M == 15:
				min_str = 'quarter past ' + hours[H]
			elif M == 30:
				min_str = 'half past ' + hours[H]
		elif M == 45:
			min_str = 'quarter to ' + hours[H + 1]
		else:
			min_str = hours[H] + " o' clock"
		return min_str


class Solution:

	def timeToWord(self, H, M):
		lut1 = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']
		lut2 = ["o' clock", 'minute', 'minutes', 'quarter', 'half', 'past', 'to']
		res = []
		if M == 0:
			res.append(lut1[H])
			res.append(lut2[0])
		elif M == 1:
			res.append(lut1[M])
			res.append(lut2[1])
			res.append(lut2[5])
			res.append(lut1[H])
		elif M == 15:
			res.append(lut2[3])
			res.append(lut2[5])
			res.append(lut1[H])
		elif M == 30:
			res.append(lut2[4])
			res.append(lut2[5])
			res.append(lut1[H])
		elif M == 45:
			res.append(lut2[3])
			res.append(lut2[6])
			res.append(lut1[H % 12 + 1])
		elif M == 59:
			res.append(lut1[60 - M])
			res.append(lut2[1])
			res.append(lut2[6])
			res.append(lut1[H % 12 + 1])
		elif M in range(2, 30):
			res.append(lut1[M])
			res.append(lut2[2])
			res.append(lut2[5])
			res.append(lut1[H])
		elif M in range(31, 59):
			res.append(lut1[60 - M])
			res.append(lut2[2])
			res.append(lut2[6])
			res.append(lut1[H % 12 + 1])
		else:
			pass
		return ' '.join(res)


class Solution:

	def timeToWord(self, H, M):
		hours = ['twelve', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']
		minutes = ["o' clock", 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'quarter', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine', 'half']
		if H < 1 or H > 12 or M < 0 or (M > 59):
			return 'Invalid time'
		if M == 0:
			minute_word = minutes[0]
		elif M <= 30:
			if M == 15:
				minute_word = minutes[15]
			elif M == 30:
				minute_word = minutes[30]
			else:
				minute_word = minutes[M] + ' minute' + ('s' if M != 1 else '')
			minute_word += ' past'
		else:
			remaining_minutes = 60 - M
			if remaining_minutes == 15:
				minute_word = minutes[15]
			else:
				minute_word = minutes[remaining_minutes] + ' minute' + ('s' if remaining_minutes != 1 else '')
			minute_word += ' to'
			H += 1
			if H > 12:
				H = 1
		hour_word = hours[H]
		if M == 0:
			return hour_word + ' ' + minute_word
		else:
			return minute_word + ' ' + hour_word


class Solution:

	def timeToWord(self, H, M):
		maptime = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 21: 'twenty one', 22: 'twenty two', 23: 'twenty three', 24: 'twenty four', 25: 'twenty five', 26: 'twenty six', 27: 'twenty seven', 28: 'twenty eight', 29: 'twenty nine'}
		if M == 0:
			return maptime[H] + " o' clock"
		elif M == 1:
			return maptime[M] + ' minute past ' + maptime[H]
		elif M == 15:
			return 'quarter past ' + maptime[H]
		elif M == 30:
			return 'half past ' + maptime[H]
		elif M > 0 and M < 30:
			return maptime[M] + ' minutes past ' + maptime[H]
		if M == 45:
			if H < 12:
				return 'quarter to ' + maptime[H + 1]
			else:
				return 'quarter to ' + maptime[1]
		elif M > 30 and M < 59:
			if H < 12:
				return maptime[60 - M] + ' minutes to ' + maptime[H + 1]
			else:
				return maptime[60 - M] + ' minutes to ' + maptime[1]
		elif M == 59:
			if H < 12:
				return maptime[60 - M] + ' minute to ' + maptime[H + 1]
			else:
				return maptime[60 - M] + ' minute to ' + maptime[1]


class Solution:

	def timeToWord(self, H, M):
		dic = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty', 60: 'sixty'}
		if M == 0:
			return "{} o'clock".format(dic[H])
		if 0 < M <= 20 and M != 15:
			if M > 1:
				return '{} minute{} past {}'.format(dic[M], 's', dic[H])
			else:
				return '{} minute{} past {}'.format(dic[M], '', dic[H])
		if 20 < M < 30 and M != 15:
			first = M // 10 * 10
			second = M % 10
			if first != 0 and second != 0:
				name = dic[M // 10 * 10] + ' ' + dic[M % 10]
			elif first != 0 and second == 0:
				name = dic[first]
			else:
				name = dic[second]
			return '{} minutes past {}'.format(name, dic[H])
		if M == 15:
			return 'quarter past {}'.format(dic[H])
		if M == 30:
			return 'half past {}'.format(dic[H])
		if M == 45:
			if H == 12:
				return 'quarter to one'
			else:
				return 'quarter to {}'.format(dic[H + 1])
		if 0 < 60 - M <= 20:
			if 60 - M > 1 and H == 12:
				return '{} minutes to {}'.format(dic[60 - M], dic[1])
			elif 60 - M > 1:
				return '{} minutes to {}'.format(dic[60 - M], dic[H + 1])
			else:
				return '{} minute to {}'.format(dic[60 - M], dic[H + 1])
		if 20 < 60 - M < 30:
			first = (60 - M) // 10 * 10
			second = (60 - M) % 10
			if first != 0 and second != 0:
				name = dic[first] + ' ' + dic[second]
			elif first != 0 and second == 0:
				name = dic[first]
			else:
				name = dic[second]
			if H == 12:
				return '{} minutes to {}'.format(name, dic[1])
			else:
				return '{} minutes to {}'.format(name, dic[H + 1])


num_to_text = ['midnight', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']

class Solution:

	def timeToWord(self, h, m):
		next_h = h + 1 if h < 12 else 1
		if m == 0:
			return num_to_text[h] + " o' clock"
		if m == 1:
			return 'one minute past ' + num_to_text[h]
		if m == 15:
			return 'quarter past ' + num_to_text[h]
		if m < 30:
			return num_to_text[m] + ' minutes past ' + num_to_text[h]
		if m == 30:
			return 'half past ' + num_to_text[h]
		if m == 45:
			return 'quarter to ' + num_to_text[next_h]
		if m == 59:
			return 'one minute to ' + num_to_text[next_h]
		if m > 30:
			return num_to_text[60 - m] + ' minutes to ' + num_to_text[next_h]


class Solution:

	def timeToWord(self, H, M):
		Hours = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'one']
		if M == 0:
			return Hours[H - 1] + " o' clock"
		minutes = {1: 'one minute', 2: 'two minutes', 3: 'three minutes', 4: 'four minutes', 5: 'five minutes', 6: 'six minutes', 7: 'seven minutes', 8: 'eight minutes', 9: 'nine minutes', 10: 'ten minutes', 11: 'eleven minutes', 12: 'twelve minutes', 13: 'thirteen minutes', 14: 'fourteen minutes', 15: 'quarter', 16: 'sixteen minutes', 17: 'seventeen minutes', 18: 'eighteen minutes', 19: 'nineteen minutes', 20: 'twenty minutes', 21: 'twenty one minutes', 22: 'twenty two minutes', 23: 'twenty three minutes', 24: 'twenty four minutes', 25: 'twenty five minutes', 26: 'twenty six minutes', 27: 'twenty seven minutes', 28: 'twenty eight minutes', 29: 'twenty nine minutes', 30: 'half', 31: 'twenty nine minutes', 32: 'twenty eight minutes', 33: 'twenty seven minutes', 34: 'twenty six minutes', 35: 'twenty five minutes', 36: 'twenty four minutes', 37: 'twenty three minutes', 38: 'twenty two minutes', 39: 'twenty one minutes', 40: 'twenty minutes', 41: 'nineteen minutes', 42: 'eighteen minutes', 43: 'seventeen minutes', 44: 'sixteen minutes', 45: 'quarter', 46: 'fourteen minutes', 47: 'thirteen minutes', 48: 'twelve minutes', 49: 'eleven minutes', 50: 'ten minutes', 51: 'nine minutes', 52: 'eight minutes', 53: 'seven minutes', 54: 'six minutes', 55: 'five minutes', 56: 'four minutes', 57: 'three minutes', 58: 'two minutes', 59: 'one minute', 60: 'sixty minutes'}
		if M > 30:
			return minutes[M] + ' to ' + Hours[H]
		else:
			return minutes[M] + ' past ' + Hours[H - 1]


class Solution:

	def timeToWord(self, H, M):
		ones = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen')
		tens = ('ten', 'twenty')
		if M <= 30:
			if M == 0:
				return ones[H - 1] + " o' clock"
			elif M == 1:
				return 'one minute past ' + ones[H - 1]
			elif M == 10 or M == 20:
				for i in str(M):
					return tens[int(i) - 1] + ' minutes past ' + ones[H - 1]
					break
			elif M == 15:
				return 'quarter past ' + ones[H - 1]
			elif M == 30:
				return 'half past ' + ones[H - 1]
			elif M < 30:
				if M < 20:
					return ones[M - 1] + ' minutes past ' + ones[H - 1]
				else:
					for i in str(M)[::-1]:
						return tens[1] + ' ' + ones[int(i) - 1] + ' minutes past ' + ones[H - 1]
						break
		elif H < 12:
			if M == 45:
				return 'quarter to ' + ones[H]
			elif M > 30:
				b = 60 - M
				if b == 10 or b == 20:
					for i in str(b):
						return tens[int(i) - 1] + ' minutes to ' + ones[H]
						break
				elif b == 0:
					return 'zero minutes to ' + ones[H]
				elif b == 1:
					return 'one minute to ' + ones[H]
				elif b < 20:
					return ones[b - 1] + ' minutes to ' + ones[H]
				else:
					for i in str(b)[::-1]:
						return tens[1] + ' ' + ones[int(i) - 1] + ' minutes to ' + ones[H]
						break
		elif H == 12:
			if M == 45:
				return 'quarter to ' + ones[0]
			elif M > 30:
				b = 60 - M
				if b == 10 or b == 20:
					for i in str(b):
						return tens[int(i) - 1] + ' minutes to ' + ones[0]
						break
				elif b == 0:
					return 'zero minutes to ' + ones[0]
				elif b == 1:
					return 'one minute to ' + ones[0]
				elif b < 20:
					return ones[b - 1] + ' minutes to ' + ones[0]
				else:
					for i in str(b)[::-1]:
						return tens[1] + ' ' + ones[int(i) - 1] + ' minutes to ' + ones[0]
						break


class Solution:

	def timeToWord(self, H, M):
		list = {0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'fourty', 50: 'fifty'}
		if M < 30:
			x = M % 10
			y = M // 10
			sub = M - x
			if M < 21:
				if M != 15:
					if M == 1:
						str = ' minute '
					else:
						str = ' minutes '
					return list[M] + str + 'past ' + list[H]
				else:
					return 'quarter past ' + list[H]
			else:
				minutes = list[sub] + ' ' + list[x]
				if minutes == 1:
					str = ' minute '
				else:
					str = ' minutes '
				return minutes + str + 'past ' + list[H]
		elif M == 30:
			return 'half past ' + list[H]
		elif M > 30:
			M = 60 - M
			x = M % 10
			y = M // 10
			sub = M - x
			if M < 21:
				if H < 12:
					if M != 15:
						if M == 1:
							str = ' minute '
						else:
							str = ' minutes '
						return list[M] + str + 'to ' + list[H + 1]
					else:
						return 'quarter to ' + list[H + 1]
				elif M != 15:
					if M == 1:
						str = ' minute '
					else:
						str = ' minutes '
					return list[M] + str + 'to ' + list[1]
				else:
					return ('quarter to ', list[1])
			elif H < 12:
				minutes = list[sub] + ' ' + list[x]
				if minutes == 1:
					str = ' minute '
				else:
					str = ' minutes '
				return minutes + str + 'to ' + list[H + 1]
			else:
				if M == 1:
					str = ' minute '
				else:
					str = ' minutes '
				minutes = list[sub] + ' ' + list[x]
				return minutes + str + 'to ' + list[1]


class Solution:

	def timeToWord(self, H, M):
		singles = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
		teen = ['eleven', 'twelve', 'thirteen', 'fourteen', 'quarter', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
		tens = ['ten', 'twenty', 'thirty', 'fourty', 'fifty']
		ans = ''
		if H <= 9:
			ans += singles[H - 1]
		elif H == 10:
			ans = tens[0]
		else:
			ans += teen[H - 11]
		if M == 0:
			ans += " o'clock"
		elif M <= 30:
			if M == 1:
				ans = singles[0] + ' minute past ' + ans
			if M % 10 == 0 and M != 30:
				ans = tens[M // 10 - 1] + ' minutes past ' + ans
			elif M in range(2, 10):
				ans = singles[M - 1] + ' minutes past ' + ans
			elif M == 10:
				ans = teen[0] + ' minutes past ' + ans
			elif M in range(11, 20):
				if M == 15:
					ans = teen[M - 11] + ' past ' + ans
				else:
					ans = teen[M - 11] + ' minutes past ' + ans
			elif M in range(21, 30):
				ans = tens[1] + ' ' + singles[M - 21] + ' minutes past ' + ans
			elif M == 30:
				ans = 'half past ' + ans
		elif M > 30:
			if H <= 8:
				ans = singles[H]
			elif H == 9:
				ans = tens[0]
			elif H == 12:
				ans = singles[0]
			else:
				ans = teen[H - 10]
			if M == 45:
				ans = 'quarter to ' + ans
			else:
				M = 60 - M
				if M == 1:
					ans = singles[0] + ' minute to ' + ans
				elif M % 10 == 0:
					ans = tens[M // 10 - 1] + ' minutes to ' + ans
				elif M in range(2, 10):
					ans = singles[M - 1] + ' minutes to ' + ans
				elif M == 10:
					ans = teen[0] + ' minutes to ' + ans
				elif M in range(11, 20):
					if M == 15:
						ans = teen[M - 11] + ' to ' + ans
					else:
						ans = teen[M - 11] + ' minutes to ' + ans
				elif M in range(21, 30):
					ans = tens[1] + ' ' + singles[M - 21] + ' minutes to ' + ans
		return ans


class Solution:

	def timeToWord(self, H, M):
		hours = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']
		minutes = hours + ['thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']
		H %= 12
		if M == 0:
			return hours[H - 1] + " o' clock"
		past_30 = M > 30
		time = ''
		if M == 30:
			time = 'half '
		elif M in (15, 45):
			time = 'quarter '
		else:
			m = 60 - M if past_30 else M
			p = ' minutes ' if m > 1 else ' minute '
			time = minutes[m - 1] + p
		if past_30:
			time += 'to ' + hours[H]
		else:
			time += 'past ' + hours[H - 1]
		return time


class Solution:

	def timeToWord(self, H, M):
		x = ["o' clock", 'one minute', 'two minutes', 'three minutes', 'four minutes', 'five minutes', 'six minutes', 'seven minutes', 'eight minutes', 'nine minutes', 'ten minutes', 'eleven minutes', 'twelve minutes', 'thirteen minutes', 'fourteen minutes', 'quarter', 'sixteen minutes', 'seventeen minutes', 'eighteen minutes', 'nineteen minutes', 'twenty minutes', 'twenty one minutes', 'twenty two minutes', 'twenty three minutes', 'twenty four minutes', 'twenty five minutes', 'twenty six minutes', 'twenty seven minutes', 'twenty eight minutes', 'twenty nine minutes', 'half']
		y = ['None', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve']
		if M == 0:
			return y[H] + ' ' + str(x[0])
		elif M > 0 and M <= 30:
			return str(x[M]) + ' ' + 'past' + ' ' + y[H]
		elif M > 30 and M <= 59:
			if H != 12:
				t = 60 - M
				return str(x[t]) + ' ' + 'to' + ' ' + y[H + 1]
			else:
				t = 60 - M
				H = 0
				return str(x[t]) + ' ' + 'to' + ' ' + y[H + 1]


class Solution:

	def timeToWord(self, H, M):
		adict = {0: '', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty'}
		if M == 0:
			return adict[H] + " o' clock"
		elif M <= 30:
			if M == 1:
				return adict[M] + ' minute past ' + adict[H]
			elif M == 15:
				return 'quarter past ' + adict[H]
			elif M == 30:
				return 'half past ' + adict[H]
			elif M % 10 == 0 or M < 21:
				return adict[M] + ' minutes past ' + adict[H]
			m = M - M % 10
			l = M % 10
			return adict[m] + ' ' + adict[l] + ' minutes past ' + adict[H]
		else:
			if H == 12:
				H = 1
			else:
				H += 1
			M = 60 - M
			if M == 1:
				return adict[M] + ' minute to ' + adict[H]
			elif M == 15:
				return 'quarter to ' + adict[H]
			elif M % 10 == 0 or M < 21:
				return adict[M] + ' minutes to ' + adict[H]
			m = M - M % 10
			l = M % 10
			return adict[m] + ' ' + adict[l] + ' minutes to ' + adict[H]


class Solution:

	def timeToWord(self, H, M):
		d = {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 21: 'twenty one', 22: 'twenty two', 23: 'twenty three', 24: 'twenty four', 25: 'twenty five', 26: 'twenty six', 27: 'twenty seven', 28: 'twenty eight', 29: 'twenty nine', 30: 'thirty'}
		if M == 0:
			return d[H] + " o'clock"
		elif M == 1:
			return d[M] + ' minute past ' + d[H]
		elif M < 15:
			return d[M] + ' minutes past ' + d[H]
		elif M == 15:
			return 'quarter past ' + d[H]
		elif M < 30:
			return d[M] + ' minutes past ' + d[H]
		elif M == 30:
			return 'half past ' + d[H]
		elif M < 45:
			if (H + 1) % 12 == 0:
				k = 12
			else:
				k = (H + 1) % 12
			return d[60 - M] + ' minutes to ' + d[k]
		elif M == 45:
			if (H + 1) % 12 == 0:
				k = 12
			else:
				k = (H + 1) % 12
			return 'quarter to ' + d[k]
		elif M == 59:
			if (H + 1) % 12 == 0:
				k = 12
			else:
				k = (H + 1) % 12
			return d[60 - M] + ' minute to ' + d[k]
		elif M < 60:
			if (H + 1) % 12 == 0:
				k = 12
			else:
				k = (H + 1) % 12
			return d[60 - M] + ' minutes to ' + d[k]
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(H, M) = input().split()
		H = int(H)
		M = int(M)
		ob = Solution()
		print(ob.timeToWord(H, M))


class Solution:

	def timeToWord(self, H, M):
		l = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'quarter', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine', 'half']
		mins = '' if M in (15, 30, 45) else ' minute' if M in (1, 59) else ' minutes'
		if M == 0:
			return l[H - 1] + ' ' + "o' clock"
		elif M > 30:
			return l[59 - M] + mins + ' to ' + l[H % 12]
		else:
			return l[M - 1] + mins + ' past ' + l[H - 1]
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(H, M) = input().split()
		H = int(H)
		M = int(M)
		ob = Solution()
		print(ob.timeToWord(H, M))


class Solution:

	def timeToWord(self, H, M):
		nums = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine']
		h = H
		m = M
		if m == 0:
			return ''.join(map(str, (nums[h], " o' clock")))
		elif m == 1:
			return ' '.join(map(str, ('one minute past', nums[h])))
		elif m == 59:
			return ' '.join(map(str, ('one minute to', nums[h % 12 + 1])))
		elif m == 15:
			return ' '.join(map(str, ('quarter past', nums[h])))
		elif m == 30:
			return ' '.join(map(str, ('half past', nums[h])))
		elif m == 45:
			return ' '.join(map(str, ('quarter to', nums[h % 12 + 1])))
		elif m < 30:
			return ' '.join(map(str, (nums[m], 'minutes past', nums[h])))
		elif m > 30:
			return ' '.join(map(str, (nums[60 - m], 'minutes to', nums[h % 12 + 1])))
if __name__ == '__main__':
	T = int(input())
	for i in range(T):
		(H, M) = input().split()
		H = int(H)
		M = int(M)
		ob = Solution()
		print(ob.timeToWord(H, M))


class Solution:

	def timeToWord(self, H, M):
		h = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'one']
		x = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'quarter', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty one', 'twenty two', 'twenty three', 'twenty four', 'twenty five', 'twenty six', 'twenty seven', 'twenty eight', 'twenty nine', 'half']
		mins = '' if M in (15, 30, 45) else ' minute' if M in (1, 59) else ' minutes'
		if M == 0:
			return x[H - 1] + ' ' + "o' clock"
		elif M > 30:
			return x[59 - M] + mins + ' to ' + h[H]
		else:
			return x[M - 1] + mins + ' past ' + x[H - 1]


class Solution:

	def timeToWord(self, H, M):
		hour = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty']
		if M == 0:
			return "{} o' clock".format(hour[H - 1])
		HH = H
		if H == 12:
			HH = 0
		if M != 0:
			if M == 1:
				return '{} minute past {}'.format(hour[M - 1], hour[H - 1])
			if M <= 20 and M != 15:
				return '{} minutes past {}'.format(hour[M - 1], hour[H - 1])
			if M == 15:
				return 'quarter past {}'.format(hour[H - 1])
			if M >= 21 and M <= 29:
				return '{} {} minutes past {}'.format(hour[19], hour[M - 21], hour[H - 1])
			if M == 30:
				return 'half past {}'.format(hour[H - 1])
			if M >= 31 and M <= 39:
				return '{} {} minutes to {}'.format(hour[19], hour[60 - M - 21], hour[HH])
			if M == 45:
				return 'quarter to {}'.format(hour[HH])
			if M == 59:
				return '{} minute to {}'.format(hour[61 - M - 2], hour[HH])
			if M >= 40:
				return '{} minutes to {}'.format(hour[61 - M - 2], hour[HH])


class Solution:

	def timeToWord(self, H, M):
		number_map = {0: 'twelve', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 20: 'twenty', 30: 'thirty', 40: 'thirty', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen'}
		if M == 0:
			return "{} o' clock".format(number_map[H])
		elif M == 15:
			return 'quarter past {}'.format(number_map[H])
		elif M == 30:
			return 'half past {}'.format(number_map[H])
		elif M == 45:
			return 'quarter to {}'.format(number_map[(H + 1) % 12])
		elif M > 30:
			if 60 - M in number_map.keys():
				minutes = number_map[60 - M]
			else:
				minutes = ''
				if (60 - M) // 10:
					minutes += number_map[10 * ((60 - M) // 10)]
					minutes += ' '
				if (60 - M) % 10:
					minutes += number_map[(60 - M) % 10]
			if minutes == 'one':
				return '{} minute to {}'.format(minutes, number_map[(H + 1) % 12])
			else:
				return '{} minutes to {}'.format(minutes, number_map[(H + 1) % 12])
		else:
			if M in number_map.keys():
				minutes = number_map[M]
			else:
				minutes = ''
				if M // 10:
					minutes += number_map[10 * (M // 10)]
					minutes += ' '
				if M % 10:
					minutes += number_map[M % 10]
			if minutes == 'one':
				return '{} minute past {}'.format(minutes, number_map[H])
			else:
				return '{} minutes past {}'.format(minutes, number_map[H])


NUMBERS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
TENS = ['twenty', 'thirty', 'fourty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
for word in TENS:
	NUMBERS.append(word)
	for i in range(1, 10):
		NUMBERS.append(' '.join([word, NUMBERS[i]]))

class Solution:

	def timeToWord(self, H, M):
		if M is 0:
			return "{} o' clock".format()
		if M is 1:
			return '{} minute past {}'.format(NUMBERS[M], NUMBERS[H])
		if M is 15:
			return 'quarter past {}'.format(NUMBERS[H])
		if M is 30:
			return 'half past {}'.format(NUMBERS[H])
		if M is 45:
			return 'quarter to {}'.format(NUMBERS[H + 1 if H < 12 else 1])
		if M is 59:
			return '{} minute to {}'.format(NUMBERS[1], NUMBERS[H + 1 if H < 12 else 1])
		if M <= 30:
			return '{} minutes past {}'.format(NUMBERS[M], NUMBERS[H])
		return '{} minutes to {}'.format(NUMBERS[60 - M], NUMBERS[H + 1 if H < 12 else 1])