play-with-string-4

Suppose you have a string S which has length N and is indexed from 0 to N−1. String R is the reverse of the string S. The string S is funny if the condition |Si−Si−1|=|Ri−Ri−1| is true for every i from 1 to N−1.

(Note: Given a string str, stri denotes the ascii value of the ith character (0-indexed) of str. |x| denotes the absolute value of an integer x)

SAMPLE INPUT
2
acxz
bcxz

SAMPLE OUTPUT
Funny
Not Funny

Explanation

Consider the 1st testcase acxz :

c-a
=
x-z
= 2

z-x
=
a-c
= 2

Consider the 2st testcase bcxz

|c-b| != |x-z|

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
for _ in range(int(input())):
	s = list(map(ord, input().strip()))
	r = s[::-1]
	ans = "Funny"
	for i in range(1, len(s)):
		if abs(s[i] - s[i-1]) != abs(r[i] - r[i-1]):
			ans = "Not Funny"
			break
	print(ans)	


for i in range(eval(input())):
	st = input()
	rs = st[::-1]
	x = len(st)
	fl = 0
	for i in range(1, x):
		if abs(ord(st[i]) - ord(st[i-1])) != abs(ord(rs[i]) - ord(rs[i-1])):
			fl = 1
			break
	if fl == 1:
		print("Not Funny")
	else:
		print("Funny")


testCases=eval(input())

while testCases>0:
	stringy=list(input())
	length=len(stringy)
	indx=0
	flag=False
	while indx<length-1:
		if abs(ord(stringy[indx])-ord(stringy[indx+1]))!=abs(ord(stringy[length-indx-1])-ord(stringy[length-indx-2])):
			flag=True
		indx=indx+1
	if flag:
		print("Not Funny")
	else:
		print("Funny")
		
	testCases=testCases-1