extraordinarily-large-2

You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other.

Given two strings x and y, print either "x< y"(ignore space, editor issues), "x>y" or "x=y" depending on the values represented by x and y. x and y each consist of a decimal integer followed zero or more '!' characters. Each '!' represents the factorial operation. For example, "3!!" represents 3!! = 6! = 720.

Input - First line of input contains no. of testcases and each test consist of 2 lines x and y.

Ouptut - Print the required output.

SAMPLE INPUT
3
0!
1
9!!
999999999
456!!!
123!!!!!!

SAMPLE OUTPUT
x=y
x>y
x<y

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
t = eval(input())
while t:
	t-=1
	a = input()
	b = input()
	cnt1=0
	cnt2=0
	i=len(a)-1
	while i>=0 and a[i]=='!':
		i-=1
		cnt1+=1
	i=len(b)-1
	while i>=0 and b[i]=='!':
		i-=1
		cnt2+=1
	swapped = 0
	if cnt2<cnt1:
		cnt2,cnt1=cnt1,cnt2
		a,b=b,a
		swapped = 1
	a = a[:len(a)-cnt1]
	b = b[:len(b)-cnt2]
	b = int(b)
	a = int(a)
	if a==0:
		if cnt1>0:
			a=1
			cnt1-=1
	if b==0:
		if cnt2>0:
			cnt2-=1
			b=1
	flag1 = cnt1
	flag2 = cnt2
	cnt2 = cnt2-cnt1
	cnt1=0
	
	val = b
	
	while cnt2>0 and val<=a:
		b=val-1
		while b>0 and val<=a:
			val = val*b
			b-=1	
		cnt2-=1
	if swapped == 1:
		a,val = val,a
	if val > a:
		print("x<y")
	elif val == a:
		print("x=y")
	else:
		print("x>y")
	


t = eval(input())
 
while(t>0):
	q = input()
	w = input()
 
	len1 = len(q)
	len2 = len(w)
	p=0
 
	while(len1>0 and len2>0 and q[len1-1]=='!' and w[len2-1]=='!'):
		len1 = len1-1
		len2 = len2-1
		p=1
 
	num1=0
	num2=0
 
	fact1=0
	fact2=0
 
	i=len1-1
	while(i>=0 and q[i]=='!'):
		fact1=fact1+1
		i=i-1
		
	i = len2-1
	while(i>=0 and w[i]=='!'):
		fact2=fact2+1
		i = i-1
 
	num1 = int(q[:len1-fact1])
	num2 = int(w[:len2-fact2])
	
	l=0
	if(fact1!=0):
		num1,num2=num2,num1
		fact1,fact2=fact2,fact1
		l=1
	if(p==1 and num1==0):
		num1=1
	
	k = num2
	if(k==0 and fact2>0):
		k=1
	while(fact2>0):
		i = k-1
		while(i>0 and k<num1):
			k = k*i
			i=i-1
		if(k>num1):
			break
		fact2 = fact2-1
 
	if(l==1):
		k,num1=num1,k
	
	if(k==num1):
		print("x=y")
	elif(num1<k):
		print("x<y")
	else:
		print("x>y")
	
 
	t = t-1


t = eval(input())
while t:
	t-=1
	a = input()
	b = input()
	cnt1=0
	cnt2=0
	i=len(a)-1
	while i>=0 and a[i]=='!':
		i-=1
		cnt1+=1
	i=len(b)-1
	while i>=0 and b[i]=='!':
		i-=1
		cnt2+=1
	swapped = 0
	if cnt2<cnt1:
		cnt2,cnt1=cnt1,cnt2
		a,b=b,a
		swapped = 1
	a = a[:len(a)-cnt1]
	b = b[:len(b)-cnt2]
	b = int(b)
	a = int(a)
	if a==0:
		if cnt1>0:
			a=1
			cnt1-=1
	if b==0:
		if cnt2>0:
			cnt2-=1
			b=1
	flag1 = cnt1
	flag2 = cnt2
	cnt2 = cnt2-cnt1
	cnt1=0
	
	val = b
	
	while cnt2>0 and val<=a:
		b=val-1
		while b>0 and val<=a:
			val = val*b
			b-=1	
		cnt2-=1
	if swapped == 1:
		a,val = val,a
	if val > a:
		print("x<y")
	elif val == a:
		print("x=y")
	else:
		print("x>y")


t=int(input())
for j in range(t):
	x=input()
	y=input()
	fx=len(x)-1
	while (x[fx]=='!'):
		fx-=1
	numx=int(x[:fx+1])
	fx=len(x)-fx-1
	fy=len(y)-1
	while (y[fy]=='!'):
		fy-=1
	numy=int(y[:fy+1])
	fy=len(y)-fy-1

	while (numx<20 and fx>0):
		temp=1;
		for i in range(numx):
			temp*=i+1
		numx=temp
		fx-=1
	
	while (numy<20 and fy>0):
		temp=1;
		for i in range(numy):
			temp*=i+1
		numy=temp
		fy-=1

	if (fx<fy):
		print('x<y')
	elif (fx>fy):
		print('x>y')
	else:
		if (numx<numy):
			print('x<y')
		elif (numx>numy):
			print('x>y')
		else:
			print('x=y')


t = eval(input())
while t:
	t-=1
	a = input()
	b = input()
	cnt1=0
	cnt2=0
	i=len(a)-1
	while i>=0 and a[i]=='!':
		i-=1
		cnt1+=1
	i=len(b)-1
	while i>=0 and b[i]=='!':
		i-=1
		cnt2+=1
	swapped = 0
	if cnt2<cnt1:
		cnt2,cnt1=cnt1,cnt2
		a,b=b,a
		swapped = 1
	a = a[:len(a)-cnt1]
	b = b[:len(b)-cnt2]
	b = int(b)
	a = int(a)
	if a==0:
		if cnt1>0:
			a=1
			cnt1-=1
	if b==0:
		if cnt2>0:
			cnt2-=1
			b=1
	flag1 = cnt1
	flag2 = cnt2
	cnt2 = cnt2-cnt1
	cnt1=0
	
	val = b
	
	while cnt2>0 and val<=a:
		b=val-1
		while b>0 and val<=a:
			val = val*b
			b-=1	
		cnt2-=1
	if swapped == 1:
		a,val = val,a
	if val > a:
		print("x<y")
	elif val == a:
		print("x=y")
	else:
		print("x>y")