You are given a string that is made up of words separated by spaces. Your task is to find the word with highest frequency, i.e. it appears maximum times in the sentence. If multiple words have maximum frequency, then print the word that occurs first in the sentence.
Example 1:
 
Input : S = "the devil in the sky"
Output : the 2
Explanation:
The frequency of the is 2, so we return "the" and
its frequency "2" i.e., "the 2" 
Example 2:
Input : S = "this is not right"
Output : this 1
Explanation:
Every word has the frequency of "1", so we return 
"this 1" as this occurs first in the sentence. 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function maximumFrequency() that takes a string S and return the answer as a string. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1 ≤ |S| ≤ 10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

Starter code:
#User function Template for python3



def maximumFrequency (S) : 

    #Complete the function





Solutions:
def maximumFrequency(s):
	t = s.split(' ')
	d = {}
	for i in t:
		if i in d.keys():
			d[i] += 1
		else:
			d[i] = 1
	ans = ''
	count = 0
	for i in t:
		if d[i] > count:
			ans = i
			count = d[i]
	if count == 0:
		return t[0] + '1'
	else:
		return ans + ' ' + str(count)


def maximumFrequency(S):
	S = S.split(' ')
	d = {}
	max = -1
	mw = ''
	for i in S:
		if i in d:
			d[i] += 1
			if d[i] > max:
				max = d[i]
		else:
			d[i] = 1
	for i in S:
		if d[i] == max:
			mw = i
			break
	if max == -1:
		return S[0] + ' ' + '1'
	else:
		b = mw + ' ' + str(max)
		return b


def maximumFrequency(S):
	dic = {}
	S = S.split(' ')
	for i in S:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	m1 = 0
	for i in dic:
		if dic[i] > m1:
			m1 = dic[i]
	m = []
	for i in dic:
		if dic[i] == m1:
			m.append(i)
	b = []
	for i in S:
		if i in m:
			s = str(i) + ' ' + str(dic[i])
			return s


def maximumFrequency(S):
	d = {}
	for i in S.split():
		d[i] = d.get(i, 0) + 1
	max = 0
	wrd = ''
	for i in S.split():
		if d[i] > max:
			max = d[i]
			wrd = i
	return wrd + ' ' + str(max)


import math

def maximumFrequency(S):
	ans = ''
	mini = math.inf
	lst = S.split()
	n = len(lst)
	dicti = {}
	for i in range(n):
		if lst[i] not in dicti:
			dicti[lst[i]] = [i, 1]
		else:
			dicti[lst[i]][1] += 1
	lst1 = [value[1] for (key, value) in dicti.items()]
	maxi = max(lst1)
	for i in dicti:
		if dicti[i][1] == maxi:
			if dicti[i][0] < mini:
				mini = dicti[i][0]
				ans = lst[dicti[i][0]]
	return ans + ' ' + str(maxi)


def maximumFrequency(S):
	l = S.split()
	d = {}
	for i in l:
		if i not in d:
			d[i] = 0
		d[i] += 1
	m = max(list(d.values()))
	s = []
	for i in l:
		if d[i] == m:
			s.append(i)
	return s[0] + ' ' + str(m)


def maximumFrequency(S):
	s = S.split(' ')
	dict_ = {}
	mx_count = 0
	for elem in s:
		dict_.update({elem: dict_.get(elem, 0) + 1})
		mx_count = dict_[elem] if dict_[elem] > mx_count else mx_count
	for elem in s:
		if s.count(elem) == mx_count:
			return str(elem) + ' ' + str(mx_count)


def maximumFrequency(S):
	MAX = -1
	s = ''
	li = S.split(' ')
	m = {}
	for i in li:
		if i not in m:
			m[i] = 0
		m[i] += 1
	for i in li:
		if MAX < m[i]:
			MAX = m[i]
			s = i + ' ' + str(m[i])
	return s


def maximumFrequency(S):
	listt = S.split(' ')
	map = {}
	for i in range(0, len(listt)):
		if listt[i] in map:
			map[listt[i]] += 1
		else:
			map[listt[i]] = 1
	word = ''
	count = 0
	for i in range(0, len(listt)):
		if map[listt[i]] > count:
			count = map[listt[i]]
			word = listt[i]
	return word + ' ' + str(count)


def maximumFrequency(S):
	S = list(S.split())
	dic = {}
	m = 0
	word = ''
	for i in S:
		if i not in dic:
			dic[i] = 0
		dic[i] += 1
	for i in S:
		if m < dic[i]:
			m = dic[i]
			word = i
	return str(word) + ' ' + str(m)


def maximumFrequency(S):
	lst = S.split()
	map = {}
	for i in lst:
		if i in map:
			map[i] += 1
		else:
			map[i] = 1
	mx = 0
	word = None
	for i in map:
		if map[i] > mx:
			mx = map[i]
			word = i
		elif map[i] == mx:
			indx = lst.index(i)
			indx_curr = lst.index(word)
			if indx < indx_curr:
				word = i
	st = ''
	st += word
	st += ' '
	st += str(mx)
	return st


def maximumFrequency(S):
	S = S.split()
	maxNum = 1
	maxWord = S[0]
	isOnlyMax = True
	theFirstMax = ''
	dict = {}
	for i in S:
		if dict.get(i) == None:
			if 1 == maxNum:
				isOnlyMax = False
				if S.index(i) < S.index(maxWord):
					maxWord = i
			dict.update({i: 1})
		else:
			if dict.get(i) + 1 == maxNum:
				isOnlyMax = False
				if S.index(i) < S.index(maxWord):
					maxWord = i
			elif dict.get(i) + 1 > maxNum:
				maxNum += 1
				maxWord = i
				isOnlyMax = False
			dict.update({i: dict.get(i) + 1})
	return maxWord + ' ' + str(maxNum)


def maximumFrequency(S):
	S = S.split()
	d = {}
	for i in range(len(S)):
		if S[i] in d:
			d[S[i]][0] += 1
		else:
			d[S[i]] = [1, i]
	max1 = 0
	res = 0
	ind = 10 ** 5
	for (i, j) in d.items():
		if j[0] > max1:
			max1 = j[0]
			res = i
			ind = j[1]
		elif j[0] == max1:
			if ind > j[1]:
				ind = j[1]
				res = i
	return res + ' ' + str(max1)


def maximumFrequency(S):
	li = S.split()
	n = len(li)
	dp = {}
	for i in range(n):
		if li[i] in dp.keys():
			dp[li[i]] += 1
		else:
			dp[li[i]] = 1
	ma = 0
	val = ''
	for j in li:
		if dp[j] > ma:
			val = j
			ma = dp[j]
	if ma == 1:
		return li[0] + ' 1'
	return val + ' ' + str(ma)


def maximumFrequency(S):
	S = S.split(' ')
	d = dict()
	freq = 0
	c = ''
	for i in range(len(S)):
		d[S[i]] = d.get(S[i], 0) + 1
	for i in S:
		if d[i] > freq:
			c = i
			freq = d[i]
	return c + ' ' + str(freq)


def maximumFrequency(S):
	li = S.split(' ')
	freq = {}
	for ele in li:
		freq[ele] = freq.get(ele, 0) + 1
	maxi = -1
	string = ''
	ans = ''
	for word in li:
		if freq[word] > maxi:
			maxi = freq[word]
			string = word
	ans += string
	ans += ' '
	ans += str(maxi)
	return ans


def maximumFrequency(s):
	s = s.split()
	d = {}
	for i in s:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	mx = 0
	for i in s:
		if d[i] > mx:
			mx = d[i]
			t = i
	return t + ' ' + str(mx)


def maximumFrequency(S):
	li = S.split(' ')
	freq = {}
	for ele in li:
		freq[ele] = freq.get(ele, 0) + 1
	maxi = 0
	ans = 0
	ans2 = ''
	for i in range(len(li)):
		if freq[li[i]] > maxi:
			maxi = freq[li[i]]
			ans = li[i]
			ans2 = ans + ' ' + str(maxi)
	return ans2


from collections import Counter

def maximumFrequency(S):
	l = S.split(' ')
	dect = {}
	for i in l:
		if i not in dect.keys():
			dect[i] = 1
		else:
			dect[i] += 1
	ans = ''
	count = 0
	for i in l:
		if dect[i] > count:
			ans = i
			count = dect[i]
	if count == 1:
		return l[0] + ' 1'
	return ans + ' ' + str(count)


def maximumFrequency(S):
	l = S.split(' ')
	dect = {}
	for i in l:
		if i not in dect.keys():
			dect[i] = 1
		else:
			dect[i] += 1
	ans = ''
	count = 0
	for i in l:
		if dect[i] > count:
			ans = i
			count = dect[i]
	if count == 1:
		return l[0] + ' 1'
	return ans + ' ' + str(count)


def maximumFrequency(S):
	S = [v for v in S.split()]
	d = dict()
	for i in S:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	kl = list(d.keys())
	vl = list(d.values())
	S.sort(key=lambda x: -d[x])
	al = [S[0], str(S.count(S[0]))]
	ans = ' '.join(al)
	return ans


def maximumFrequency(S):
	li = S.split(' ')
	d = {}
	for i in li:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	a = max(d.values())
	res = ''
	for i in li:
		if d[i] >= a:
			res += i + ' ' + str(a)
			break
	return res


def maximumFrequency(S):
	S = S.split(' ')
	d = dict()
	for i in S:
		d[i] = d.get(i, 0) + 1
	maxi = 0
	for i in S:
		if d[i] > maxi:
			maxi = d[i]
			c = i
	return c + ' ' + str(maxi)


def maximumFrequency(S):
	lst = S.split()
	dic = {}
	for i in lst:
		if i not in dic:
			dic[i] = 0
		dic[i] += 1
	mx_val = 0
	for i in lst:
		if dic[i] > mx_val:
			mx_val = dic[i]
			ans = i
	return ans + ' ' + str(mx_val)


def maximumFrequency(S):
	d = {}
	S = S.split(' ')
	for i in S:
		if i in d:
			d[i] = d[i] + 1
		else:
			d[i] = 1
	val = max(zip(d.values(), d.keys()))[1]
	s = ''
	s = s + val + ' '
	mx = -1
	mx1 = d[S[0]]
	k = S[0]
	for j in S:
		mx = max(d[j], mx)
		if mx > mx1:
			mx1 = max(d[j], mx)
			k = j
	s = k + ' ' + str(mx)
	return s


def maximumFrequency(S):
	dic = {}
	arr = S.split(' ')
	c = 0
	maxx = 0
	word = ''
	for e in arr:
		try:
			c = dic[e] + 1
			dic[e] = c
		except:
			dic[e] = 1
			c = 1
	maxx = 0
	for e in arr:
		c = dic[e]
		if c > maxx:
			word = e
			maxx = c
	return word + ' ' + str(maxx)


def maximumFrequency(S):
	store = {}
	word = S.split(' ')
	for i in word:
		if i not in store:
			store[i] = 1
		else:
			store[i] += 1
	ans = ''
	count = 0
	for i in word:
		if store[i] > count:
			ans = i
			count = store[i]
	ans += ' ' + str(count)
	return ans


def maximumFrequency(S):
	d1 = {}
	li = S.split(' ')
	max1 = -100000
	string = ''
	for i in li:
		d1[i] = d1.get(i, 0) + 1
	for i in d1:
		if d1.get(i) > max1:
			max1 = d1.get(i)
	for i in li:
		if d1.get(i) == max1:
			string += i
			string += ' '
			string += str(d1.get(i))
			break
	return string


def maximumFrequency(s):
	s = list(s.split())
	d = dict()
	for i in s:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	maxfr = max(d.values())
	l = []
	for i in d:
		if d[i] == maxfr:
			l.append(s.index(i))
	return str(s[min(l)]) + ' ' + str(maxfr)


def maximumFrequency(S):
	dt = dict()
	ls = S.split(' ')
	for word in ls:
		if word in dt.keys():
			dt[word] += 1
		else:
			dt[word] = 1
	ans = ''
	count = 0
	for word in ls:
		if dt[word] > count:
			ans = word
			count = dt[word]
	ans += ' ' + str(count)
	return ans


def maximumFrequency(S):
	S = S.split()
	d = {}
	for i in S:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	ans = S[0]
	for j in S:
		if d[j] > d[ans]:
			ans = j
	a = str(d[ans])
	s = ''
	s = s + ans + ' ' + a
	return s


from collections import defaultdict

def maximumFrequency(s):
	m = defaultdict(int)
	n = len(s)
	v = []
	temp = ''
	ans = ''
	maxi = 0
	for i in range(n):
		if s[i] == ' ':
			v.append(temp)
			temp = ''
		else:
			temp += s[i]
	v.append(temp)
	for i in range(len(v)):
		m[v[i]] += 1
	for i in range(len(v)):
		if m[v[i]] > maxi:
			maxi = m[v[i]]
			ans = v[i]
	return ans + ' ' + str(maxi)


from collections import OrderedDict

def maximumFrequency(S):
	words = S.split()
	OD = OrderedDict()
	for word in words:
		if word not in OD:
			OD[word] = 1
		else:
			OD[word] += 1
	maxi = max(OD.values())
	for item in OD:
		if OD[item] == maxi:
			return item + ' ' + str(maxi)


from collections import OrderedDict

def maximumFrequency(S):
	stri = S.split()
	d = OrderedDict()
	for i in stri:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = []
	for i in d:
		ans.append([i, d[i]])
	ans = sorted(ans, key=lambda x: x[1], reverse=True)
	l = ans[0]
	s = l[0] + ' ' + str(l[1])
	return s


def maximumFrequency(S):
	dic = {}
	S = S.split(' ')
	for i in S:
		if i not in dic:
			dic[i] = 1
		else:
			dic[i] += 1
	maxi = max(dic.values())
	for i in S:
		if dic[i] == maxi:
			return i + ' ' + str(maxi)
	return


def maximumFrequency(S):
	S = S.split()
	d = {}
	for i in S:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = ''
	count = 0
	for i in S:
		if d[i] > count:
			ans = i
			count = d[i]
	return ans + ' ' + str(count)


from collections import OrderedDict

def maximumFrequency(S):
	d = OrderedDict()
	valu = 0
	for i in S.split(' '):
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	for i in d:
		if d[i] > valu:
			k = i
			valu = d[i]
	return str(k) + ' ' + str(valu)


def maximumFrequency(S):
	lis = S.split(' ')
	dic = {}
	m = -1
	for i in range(len(lis)):
		if lis[i] in dic:
			dic[lis[i]] += 1
		else:
			dic[lis[i]] = 1
	for i in dic.keys():
		m = max(m, dic[i])
	for i in range(len(lis)):
		if dic[lis[i]] == m:
			return lis[i] + ' ' + str(m)


def maximumFrequency(S):
	b = S.split()
	d = {}
	for i in range(len(b)):
		if b[i] not in d.keys():
			d[b[i]] = 1
		else:
			d[b[i]] += 1
	n = ''
	v = 0
	for i in range(len(b)):
		if d[b[i]] > v:
			v = d[b[i]]
			n = b[i]
	c = str(v)
	g = ' '
	h = g + c
	d = n + h
	return d


def maximumFrequency(S):
	from collections import Counter
	S = S.split(' ')
	f = Counter(S)
	arr = []
	fmax = max(f.values())
	if fmax > 1:
		for (i, v) in enumerate(S):
			if S.count(v) == fmax:
				arr.append(v)
				break
		return arr[0] + ' ' + str(fmax)
	else:
		return S[0] + ' 1'


def maximumFrequency(S):
	x = S.split()
	t = {}
	m = 0
	ans = ''
	l = 0
	for item in x:
		if item in t:
			t[item] += 1
		else:
			t[item] = 1
	for i in x:
		l = t[i]
		if m < l:
			m = l
			ans = i + ' ' + str(m)
	return ans


def maximumFrequency(s):
	lst = s.split(' ')
	maxi = -float('inf')
	from collections import OrderedDict
	d = OrderedDict()
	ans = ''
	for i in lst:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in d.keys():
		if d[i] > maxi:
			maxi = d[i]
			ans = i
	return ans + ' ' + str(maxi)


def maximumFrequency(S):
	d = {}
	l = S.split(' ')
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	m = -1
	for i in l:
		if d[i] > m:
			m = d[i]
			w = i
	s = w + ' ' + str(m)
	return s


def maximumFrequency(s):
	l = s.split(' ')
	d = {}
	for i in range(len(l)):
		if l[i] not in d:
			d[l[i]] = 0
			d[l[i]] += 1
		else:
			d[l[i]] += 1
	max = d[l[0]]
	x = l[0]
	for i in l:
		if max < d[i]:
			x = i
			max = d[i]
	x = x + ' ' + str(max)
	return x


def maximumFrequency(S):
	words = S.split()
	words = words[::-1]
	freq = {}
	ans = ''
	maxi = 0
	for word in words:
		freq[word] = freq.get(word, 0) + 1
		if freq[word] >= maxi:
			maxi = max(maxi, freq[word])
			ans = word
	return ans + ' ' + str(maxi)


def maximumFrequency(S):
	S = S.split()
	dict = {}
	result = []
	for element in S:
		dict[element] = dict.get(element, 0) + 1
	maxi = max(dict.values())
	for element in S:
		if dict[element] == maxi:
			result.append(str(element))
			result.append(str(maxi))
			break
	return ' '.join(result)


def maximumFrequency(S):
	l = S.split(' ')
	m = {}
	mx = 1
	for i in l:
		if i in m:
			m[i] += 1
			mx = max(mx, m[i])
		else:
			m[i] = 1
	for i in l:
		if m[i] == mx:
			return i + ' ' + str(mx)


def maximumFrequency(S):
	list1 = S.split(' ')
	d = {}
	for i in list1:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
	st = ''
	maxi = 0
	for i in list1:
		if d[i] > maxi:
			maxi = d[i]
			st = i + ' ' + str(maxi)
	return st


from collections import OrderedDict

def maximumFrequency(S):
	d = OrderedDict()
	s = S.split()
	for i in s:
		try:
			d[i] += 1
		except:
			d[i] = 1
	m = max(d.values())
	for i in d:
		if m == d[i]:
			return str(i) + ' ' + str(d[i])


def maximumFrequency(S):
	words = S.split()
	d = {}
	for i in words:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	Max = 0
	ans = ''
	for i in words:
		if d[i] > Max:
			Max = d[i]
			ans = i
	return ans + ' ' + str(Max)


def maximumFrequency(S):
	words = S.split()
	frequency = CountFreq(words)
	word = ''
	current_max_freq = 0
	for item in words:
		if frequency[item] > current_max_freq:
			current_max_freq = frequency[item]
			word = item
	s = word + ' ' + str(current_max_freq)
	return s

def CountFreq(words):
	freq = {}
	for item in words:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq


def maximumFrequency(S):
	elem = S.split(' ')
	hmap = {}
	maxi = 0
	res = ''
	for i in elem:
		if i not in hmap:
			hmap[i] = 1
		else:
			hmap[i] += 1
	for i in elem:
		if hmap[i] > maxi:
			res = i
			maxi = hmap[i]
	if maxi == 1:
		return elem[0] + ' ' + '1'
	return res + ' ' + str(maxi)


def maximumFrequency(S):
	S = S.split()
	dic = {}
	for i in S:
		if i not in dic:
			dic[i] = 1
		else:
			dic[i] += 1
	res = 0
	ans = ''
	for j in S:
		if res < dic[j]:
			res = dic[j]
			ans = j
	if res == 1:
		return S[0] + ' 1'
	return ans + ' ' + str(res)


def maximumFrequency(S):
	ls = S.split()
	d = dict()
	for i in ls:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	word = ''
	maxFreq = 0
	for i in ls:
		if d[i] > maxFreq:
			maxFreq = d[i]
			word = i
	s = word + ' ' + str(maxFreq)
	return s


from collections import OrderedDict

def maximumFrequency(S):
	mdict = OrderedDict()
	strResult = ''
	maxFreq = -1
	S = S.split(' ')
	for item in S:
		if item in mdict:
			mdict[item] = mdict[item] + 1
		else:
			mdict[item] = 1
	for (k, v) in mdict.items():
		if v > maxFreq:
			maxFreq = v
			strResult = k + ' ' + str(v)
	return strResult


def maximumFrequency(S):
	d = {}
	l = S.split()
	for i in S.split():
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	Max = 0
	chr = ''
	for i in l:
		if Max < d[i]:
			Max = d[i]
			chr = i
	if Max == 1:
		return l[0] + ' 1'
	return chr + ' ' + str(Max)


from collections import Counter

def maximumFrequency(S):
	x = 0
	p = ''
	a = S.split(' ')
	c = Counter(a)
	for k in a:
		if c[k] > x:
			x = c[k]
			p = k
	s = p + ' ' + str(x)
	return s


def maximumFrequency(S):
	l = S.split()
	s = {}
	m = -1
	for i in l:
		if i in s:
			s[i] += 1
		else:
			s[i] = 1
	for i in l:
		if s[i] > m:
			m = s[i]
			t = i + ' ' + str(s[i])
	return t


def maximumFrequency(S):
	lst = S.split()
	max_val = 0
	d = {}
	for i in range(len(lst)):
		if lst[i] in d:
			d[lst[i]] += 1
		else:
			d[lst[i]] = 1
	for i in range(len(lst)):
		if d[lst[i]] > max_val:
			max_val = d[lst[i]]
			res = lst[i]
	return '{} {}'.format(res, max_val)


def maximumFrequency(S):
	arr = S.split(' ')
	d = {}
	for word in arr:
		if word not in d.keys():
			d[word] = 1
		else:
			d[word] += 1
	count = 0
	for item in arr:
		if d[item] > count:
			count = d[item]
			word = item
	return word + ' ' + str(count)


from collections import OrderedDict

def maximumFrequency(S):
	arr = S.split(' ')
	d = OrderedDict()
	for i in arr:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	ans = max(d, key=d.get)
	cnt = max(d.values())
	res = ans + ' ' + str(cnt)
	return res


def maximumFrequency(S):
	d = {}
	S = S.split(' ')
	for i in S:
		if i not in d:
			d[i] = 1
		else:
			d[i] = d[i] + 1
	m = -1
	k = ''
	for i in S:
		if d[i] > m:
			m = d[i]
			k = i
	print(k, end=' ')
	return m


def maximumFrequency(S):
	d = {}
	l = S.split()
	for ele in l:
		d[ele] = d.get(ele, 0) + 1
	m = -1
	x = ''
	for ele in l:
		if d[ele] > m:
			m = d[ele]
			a = ele
			b = d[ele]
			x = a + ' ' + str(b)
	return x


def maximumFrequency(S):
	ls = S.split(' ')
	k = {}
	for x in ls:
		if x in k.keys():
			k[x] += 1
		else:
			k[x] = 1
	ma = max(k.values())
	lsw = []
	for x in k.keys():
		if k[x] == ma:
			lsw.append(x)
	if len(lsw) == 1:
		return lsw[0] + ' ' + str(ma)
	else:
		m = len(ls)
		for x in lsw:
			m = min(m, ls.index(x))
		return ls[m] + ' ' + str(ma)


def maximumFrequency(S):
	temp = S.split(' ')
	from collections import Counter
	freq = Counter(temp)
	val_max = max(list(freq.values()))
	ans = []
	for (k, v) in freq.items():
		if v == val_max:
			ans.append(k)
	min_ind = len(S)
	for i in ans:
		min_ind = min(min_ind, temp.index(i))
	return temp[min_ind] + ' ' + str(val_max)


def maximumFrequency(S):
	l = S.split(' ')
	h = {}
	for i in l:
		if i not in h:
			h[i] = 1
		else:
			h[i] += 1
	ans = -1
	name = ''
	for i in l:
		if h[i] > ans:
			ans = h[i]
			name = i
	return name + ' ' + str(ans)


from collections import OrderedDict

def maximumFrequency(S):
	S = S.split(' ')
	d = OrderedDict()
	s = ''
	mx = -1
	for i in S:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	c = max(d, key=d.get)
	e = max(d.values())
	return c + ' ' + str(e)


from collections import OrderedDict

def maximumFrequency(S):
	S = S.split(' ')
	d = OrderedDict()
	s = ''
	mx = -1
	for i in S:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for (k, v) in d.items():
		if v > mx:
			mx = v
			s = k + ' ' + str(v)
	return s


from collections import OrderedDict

def maximumFrequency(S):
	mdict = OrderedDict()
	strn = ''
	mxfr = -1
	S = S.split(' ')
	for item in S:
		if item in mdict:
			mdict[item] = mdict[item] + 1
		else:
			mdict[item] = 1
	for (k, v) in mdict.items():
		if v > mxfr:
			mxfr = v
			strn = k + ' ' + str(v)
	return strn
for _ in range(0, int(input())):
	S = input()
	print(maximumFrequency(S))


def maximumFrequency(S):
	s = list(S.split(' '))
	d = {}
	l = []
	for i in s:
		if i not in d.keys():
			d[i] = 1
			l.append(i)
		else:
			d[i] += 1
	ik = l[0]
	ij = d[l[0]]
	for i in l:
		if d[i] > ij:
			ik = i
			ij = d[i]
	return ik + ' ' + str(ij)
for _ in range(0, int(input())):
	S = input()
	print(maximumFrequency(S))


import numpy
from collections import Counter
from collections import OrderedDict

def maximumFrequency(S):
	s = ''
	S = S.split()
	n = numpy.unique(S)
	mxfr = -1
	dict1 = OrderedDict()
	for ele in S:
		if ele in dict1:
			dict1[ele] += 1
		else:
			dict1[ele] = 1
	for (k, v) in dict1.items():
		if v > mxfr:
			mxfr = v
			s = k + ' ' + str(v)
	return s
for _ in range(0, int(input())):
	S = input()
	print(maximumFrequency(S))


def maximumFrequency(S):
	MAX = -1
	s = ''
	li = S.split(' ')
	m = {}
	for i in li:
		if i not in m:
			m[i] = 0
		m[i] += 1
	for i in li:
		if MAX < m[i]:
			MAX = m[i]
			s = i + ' ' + str(m[i])
	return s
for _ in range(0, int(input())):
	S = input()
	print(maximumFrequency(S))


def maximumFrequency(S):
	t = S.split()
	dict_ = dict()
	for i in t:
		if i not in dict_:
			dict_[i] = 1
		else:
			dict_[i] += 1
	(k, l) = (t[0], dict_[t[0]])
	max = 1
	for word in t:
		if dict_[word] > max:
			(k, l) = (word, dict_[word])
			max = l
	return k + ' ' + str(l)
for _ in range(0, int(input())):
	S = input()
	print(maximumFrequency(S))


def maximumFrequency(S):
	l = {}
	S = S.split()
	for i in S:
		if i not in l:
			l[i] = 1
		else:
			l[i] += 1
	k = max(l.values())
	for (i, j) in enumerate(S):
		if l[j] == k:
			return (j, k)


from collections import Counter as C

def maximumFrequency(s):
	s = s.split(' ')
	z = 0
	for j in C(s).values():
		z = max(j, z)
	l = []
	for (i, j) in C(s).items():
		if z == j:
			l.append(i)
	for i in s:
		if i in l:
			return i + ' ' + str(z)


from collections import OrderedDict

def maximumFrequency(S):
	hashmap = OrderedDict()
	maxfreq = -1
	result = ''
	S = S.split(' ')
	for i in S:
		if i in hashmap:
			hashmap[i] += 1
		else:
			hashmap[i] = 1
	for (value, freq) in hashmap.items():
		if freq > maxfreq:
			maxfreq = freq
			result = value + ' ' + str(freq)
	return result


def maximumFrequency(S):
	d = {}
	for i in S.split():
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	max1 = 0
	for i in S.split():
		if max1 < d[i]:
			max1 = d[i]
			element = i
	max1 = str(max1)
	return ' '.join([element, max1])


def maximumFrequency(S):
	arr = S.split(' ')
	m = {}
	maxans = -99999
	for i in arr:
		if i in m:
			m[i] += 1
		else:
			m[i] = 1
	for i in arr:
		if m[i] > maxans:
			maxans = m[i]
			st = i
	res = st + ' ' + str(maxans)
	return res


from collections import OrderedDict

def maximumFrequency(S):
	res = S.split(' ')
	h = OrderedDict()
	ress = ''
	mxfr = -1
	for i in res:
		if i not in h:
			h[i] = 1
		else:
			h[i] += 1
	for (k, v) in h.items():
		if v > mxfr:
			mxfr = v
			ress = k + ' ' + str(v)
	return ress


from collections import OrderedDict

def maximumFrequency(s):
	wordlist = s.split()
	d = OrderedDict()
	for word in wordlist:
		if word not in d:
			d[word] = 1
		else:
			d[word] += 1
	m = max(d.values())
	for (k, v) in d.items():
		if v == m:
			ans = k + ' ' + str(v)
			return ans