------Read problems statements in Hindi,
Mandarin chinese
, Russian and Vietnamese as well. ------ 

Chef wants to set problems for a Lunchtime contest. He already has all the problem ideas and tests for them. Now, he only needs someone to test them, so he asked Hasan to do it. 

Hasan is now testing the problems, the problem that hasan is currently testing has $M$ tests (numbered $1$ through $M$). He wrote $N$ solutions (numbered $1$ through $N$) for this problem; some of the solutions are intended to pass, while other ones are intended to fail on some tests. 

He has submitted all of his solutions to this problem in a testing contest. For each solution, the system returned a (possibly empty) list of tests on which this solution failed as feedback.

There are three possible outcomes:
If there is a solution which is intended to pass all tests, but fails on some test, the tests are *invalid*.
If the tests are not invalid and there is a solution which is intended to fail on some test, but passes all tests, the tests are *weak*.
If the tests are not invalid or weak, they are *fine*.

Help Hasan determine the outcome for this problem!

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of problems that Hasan wants to test. The description of $T$ problems follows.
The first line contains two space-separated integers $N$ and $M$. 
$N$ lines follow. For each $i$ ($1 ≤ i ≤ N$), the $i$-th of these lines contains the string "correct" if the $i$-th solution is intended to pass or "wrong" if it is intended to fail, followed by a space and a string with length $M$. For each valid $j$, the $j$-th character of this string is '1' if the $i$-th solution passed the $j$-th test or '0' if it failed the $j$-th test.

------  Output ------
For each test case, print a single line containing one of the strings "FINE", "INVALID" or "WEAK".

------  Constraints  ------
$1 ≤ T ≤ 100$
$2 ≤ N, M ≤ 50$

------  Subtasks ------
Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
4
4 5
correct 11111
wrong 10101
correct 11111
wrong 01111
4 5
correct 10110
wrong 11111
correct 11111
wrong 01000
4 5
correct 11111
wrong 11111
wrong 10100
wrong 00000
4 5
wrong 10110
correct 01101
correct 11111
wrong 11000
----- Sample Output 1 ------ 
FINE
INVALID
WEAK
INVALID
----- explanation 1 ------ 
First problem: All correct submissions are passing all tests and each wrong submission is failing on at least one test, so the tests are fine.

Second problem: The first submission is failing on the second and fifth test, even though it is intended to be correct, so the tests are invalid. Note that even though the second submission indicates that the tests are also weak, the answer is still "INVALID", since you should print "WEAK" only if the tests are not invalid.

Third problem: All correct submissions are passing, so the tests are valid, but the second submission is intended to fail, yet it passes all tests, so the tests are weak.

Fourth problem: The second submission is correct, but it is not passing all tests, so the tests are invalid.

Source: codechef | Difficulty: MEDIUM
Tags: Implementation


Solutions:
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = [[x for x in input().split()] for __ in range(n)]
	res = 'FINE'
	for i in A:
		if i[0] == 'correct' and i[1].count('0') > 0:
			res = 'INVALID'
			break
		elif i[0] == 'wrong' and i[1].count('1') == m:
			res = 'WEAK'
	print(res)


for _ in range(int(input())):
	n = int(input().split()[0])
	pl = [input().split() for _ in range(n)]
	res = 'FINE'
	for i in pl:
		if i[0] == 'correct':
			if '0' in i[1]:
				res = 'INVALID'
				break
		elif i[0] == 'wrong':
			if '0' not in i[1]:
				res = 'WEAK'
	print(res)


t = int(input())
while t > 0:
	(n, m) = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append(input())
	catz = 0
	cal1 = 0
	watz = 0
	wal1 = 0
	for i in l:
		if i[:5] == 'corre' and i.count('1') == m:
			cal1 += 1
		elif i[:5] == 'corre' and i.count('0') >= 1:
			catz += 1
		elif i[:5] == 'wrong' and i.count('0') >= 1:
			watz += 1
		elif i[:5] == 'wrong' and i.count('1') == m:
			wal1 += 1
	if cal1 > 0 and watz > 0 and (catz == 0) and (wal1 == 0):
		print('FINE')
	elif cal1 > 0 and (watz > 0 or wal1 > 0) and (catz == 0):
		print('WEAK')
	else:
		print('INVALID')
	t -= 1


T = int(input())
for i in range(T):
	(N, M) = tuple([int(j) for j in input().split()])
	X = []
	for j in range(N):
		X.append(tuple(input().split()))
	for t in X:
		if t[0] == 'correct' and '0' in t[1]:
			print('INVALID')
			t = None
			break
	if t != None:
		for t in X:
			if t[0] == 'wrong' and '0' not in t[1]:
				print('WEAK')
				t = None
				break
	if t != None:
		print('FINE')


testNum = int(input())
for i in range(testNum):
	(LineNum, StrLength) = map(int, input().split())
	TestInvalid = False
	TestWeak = False
	for j in range(LineNum):
		LineArr = input().split()
		if j == LineNum - 1:
			if TestInvalid:
				print('INVALID')
			elif TestWeak:
				print('WEAK')
			else:
				print('FINE')
			TestInvalid = False
			TestWeak = False
		elif LineArr[0] == 'correct':
			if int(LineArr[1]) < int(bin(2 ** StrLength - 1)[2:]):
				TestInvalid = True
		elif int(LineArr[1]) == int(bin(2 ** StrLength - 1)[2:]):
			TestWeak = True


i = int(input())
lisk = []
for _ in range(i):
	k = input().split()
	mai = []
	for el in range(int(k[0])):
		kk = input().split()
		mai.append(kk)
	sta = 'FINE'
	for ele in mai:
		if ele[0] == 'correct' and '0' in ele[1]:
			sta = 'INVALID'
	for ele in mai:
		if ele[0] == 'wrong' and '0' not in ele[1] and (sta != 'INVALID'):
			sta = 'WEAK'
	lisk.append(sta)
for ele in lisk:
	print(ele)


t = int(input())
for i in range(t):
	n_m = input().split(' ')
	(n, m, l1, l2, l_c, f) = (int(n_m[0]), int(n_m[1]), [], [], ['FINE', 'WEAK', 'INVALID'], 0)
	for j in range(n):
		ans_st = input().split(' ')
		l1.append(ans_st[0])
		l2.append(ans_st[1])
	for x in range(n):
		if l1[x] == 'correct' and l2[x].count('1') != m:
			f = max(f, 2)
		elif l1[x] == 'wrong' and l2[x].count('1') == m:
			f = max(f, 1)
	print(l_c[f])


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	help_var = 1
	ans = 'FINE'
	for i in range(n):
		(verdict, tests) = map(str, input().split())
		for j in range(len(tests)):
			if help_var == 0:
				break
			if verdict == 'wrong' and tests == '1' * m:
				ans = 'WEAK'
				break
			elif verdict == 'correct' and tests[j] == '0':
				ans = 'INVALID'
				help_var = 0
	print(ans)


q = int(input())
for i in range(q):
	w = str(input())
	w = w + ' '
	e = ''
	r = []
	for i in w:
		if i == ' ':
			r.append(int(e))
			e = ''
		else:
			e = e + i
	s = 0
	d = 0
	for i in range(r[0]):
		t = str(input())
		t = t + ' '
		y = ''
		u = []
		for j in t:
			if j == '1' or j == '0':
				u.append(j)
			elif j == ' ':
				u.append(y)
				y = ''
			else:
				y = y + j
		if u[0] == 'correct':
			for j in range(1, len(u)):
				if u[j] == '0':
					s = s + 1
					break
		if u[0] == 'wrong':
			f = 0
			for j in range(1, len(u)):
				if u[j] == '1':
					f = f + 1
			if f == r[1]:
				d = d + 1
	if s > 0:
		print('INVALID')
	if s == 0 and d > 0:
		print('WEAK')
	if s == 0 and d == 0:
		print('FINE')


for case in range(int(input())):
	(n, m) = map(int, input().split())
	correct = ''
	weak = False
	for i in range(n):
		(c, s) = input().split()
		if c == 'correct':
			correct += s
		elif not weak and s.count('0') == 0:
			weak = True
	if correct.count('0') == 0:
		if not weak:
			print('FINE')
		else:
			print('WEAK')
	else:
		print('INVALID')


t = int(input())
while t:
	(n, m) = map(int, input().split(' '))
	result = 'FINE'
	for i in range(n):
		test1 = list(map(str, input().split(' ')))
		if 'correct' in test1:
			if '0' in test1[1]:
				result = 'INVALID'
		if 'wrong' in test1 and result != 'INVALID':
			if '0' not in test1[1]:
				result = 'WEAK'
	print(result)
	t = t - 1


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	(invalid, weak) = (False, False)
	(cor, wro) = ([], [])
	for i in range(n):
		(sta, sol) = input().split()
		if sta == 'correct':
			req = '1' * m
			if sol != req:
				invalid = True
		else:
			notreq = '1' * m
			if sol == notreq:
				weak = True
	if invalid:
		print('INVALID')
	elif weak:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(f, w) = (True, True)
	for i in range(n):
		(j, a) = input().split()
		if j == 'correct':
			if a.count('1') != len(a):
				f = False
		elif j == 'wrong':
			if a.count('0') == 0:
				w = False
	if f and w:
		print('FINE')
	elif f and (not w):
		print('WEAK')
	else:
		print('INVALID')


for t in range(int(input())):
	(n, testc) = map(int, input().split(' '))
	s = 0
	o = ''
	counter = 0
	no = 0
	printer = ['INVALID', 'WEAK', 'FINE']
	output = [0, 0, 0]
	for i in range(n):
		(sub, tes) = map(str, input().split(' '))
		su = 0
		for i in tes:
			su = su + int(i)
		if su != testc and sub == 'correct':
			o = 'INVALID'
			output[0] += 1
		if su == testc and sub == 'wrong':
			o = 'WEAK'
			output[1] += 1
		if su == testc and sub == 'correct':
			o = 'FINE'
			output[2] += 1
	if output[0] > 0:
		print('INVALID')
	elif output[1] > 0:
		print('WEAK')
	else:
		print('FINE')


for t in range(int(input())):
	(n, testc) = map(int, input().split(' '))
	xx = 'FINE'
	f = True
	for i in range(n):
		(sub, tes) = map(str, input().split(' '))
		su = 0
		if xx == 'INVALID':
			continue
		for i in tes:
			su = su + int(i)
		if su != testc and sub == 'correct':
			xx = 'INVALID'
		elif su == testc and sub == 'wrong':
			xx = 'WEAK'
	print(xx)


tc = int(input())
for _ in range(tc):
	(n, m) = map(int, input().split())
	case = 'FINE'
	force = 'STRONG'
	for i in range(n):
		(a, b) = map(str, input().split())
		b = list(b)
		if a == 'correct':
			for i in b:
				if i == '0':
					case = 'INVALID'
					break
		elif a == 'wrong':
			if max(b) == min(b):
				force = 'WEAK'
	if case == 'INVALID':
		print(case)
	elif force == 'WEAK':
		print(force)
	else:
		print(case)


def solve():
	for _ in range(int(input())):
		(cases, tests) = map(int, input().split(' '))
		grade = 'FINE'
		for _ in range(cases):
			(plan, output) = input().split(' ')
			if plan == 'correct' and '0' in output:
				grade = 'INVALID'
			elif plan == 'wrong' and '1' * tests == output and (grade != 'INVALID'):
				grade = 'WEAK'
		print(grade)
solve()


for i in range(int(input())):
	(m, n) = map(int, input().split())
	count = 0
	for i in range(0, m):
		a = list(map(str, input().split()))
		if count == 1:
			continue
		if a[0] == 'correct':
			if '0' in a[1]:
				print('INVALID')
				count = 1
		elif '0' not in a[1]:
			count = 2
	if count == 0:
		print('FINE')
	elif count == 2:
		print('WEAK')


test = int(input())
while test > 0:
	l1 = input().split(' ')
	n = int(l1[0])
	invalid = False
	weak = False
	while n > 0:
		strList = input().split(' ')
		if strList[0] == 'correct':
			if '0' in strList[1]:
				invalid = True
		elif strList[0] == 'wrong':
			if '0' not in strList[1]:
				weak = True
		n = n - 1
	if invalid:
		print('INVALID')
	elif weak:
		print('WEAK')
	else:
		print('FINE')
	test -= 1


T = int(input())
con = 0
while con < T:
	conn = 0
	intent = []
	resi = []
	inpi = input().split()
	N = int(inpi[0])
	M = int(inpi[1])
	weak = False
	invalid = False
	while conn < N:
		inp = input().split()
		tr = inp[0]
		mi = inp[1]
		intent.append(tr)
		resi.append(mi)
		conn += 1
	control = 0
	while control < len(intent):
		if intent[control] == 'correct':
			if '0' in resi[control]:
				invalid = True
		elif intent[control] == 'wrong':
			if '0' not in resi[control]:
				weak = True
		control += 1
	if invalid:
		print('INVALID')
	elif weak:
		print('WEAK')
	else:
		print('FINE')
	con += 1


for i in range(int(input())):
	(m, n) = map(int, input().split())
	l1 = []
	a = 0
	b = 0
	c = 0
	d = 0
	for i in range(m):
		l = input().split(' ')
		a1 = list(l)
		if a1[0] == 'correct' and a1[1].count('1') == n:
			a += 1
		elif a1[0] == 'correct' and a1[1].count('1') < n:
			b += 1
		elif a1[0] == 'wrong' and a1[1].count('1') < n:
			c += 1
		elif a1[0] == 'wrong' and a1[1].count('1') == n:
			d += 1
	if a >= 1 and b == 0 and (c >= 1) and (d == 0):
		print('FINE')
	elif b != 0:
		print('INVALID')
	elif b == 0 and d >= 1:
		print('WEAK')


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	ii = 0
	w = 0
	for i in range(m):
		(state, output) = input().split()
		if state == 'correct':
			if set(list(output)) != set('1'):
				ii = 1
		elif set(list(output)) == set('1'):
			w = 1
	if ii:
		print('INVALID')
	elif w:
		print('WEAK')
	else:
		print('FINE')


t = int(input())
for _ in range(t):
	(c, q) = map(str, input().split())
	(c, q) = (int(c), int(q))
	c1 = 0
	l = []
	a = True
	b = True
	for i in range(c):
		(s1, s2) = map(str, input().split())
		l.append([s1, s2])
	for i in l:
		(s1, s2) = (i[0], i[1])
		if s1 == 'correct' and s2.count('1') != q:
			a = False
		elif s1 == 'wrong' and s2.count('1') == q:
			b = False
	if a and b:
		print('FINE')
	elif a and (not b):
		print('WEAK')
	else:
		print('INVALID')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	FINE = 0
	INVALID = 0
	WEAK = 0
	for i in range(n):
		(t, l) = input().split()
		l = list(map(int, list(l)))
		if sum(l) == len(l) and t == 'correct':
			FINE = 1
		elif sum(l) < len(l) and t == 'wrong':
			FINE = 1
		elif sum(l) < len(l) and t == 'correct':
			INVALID = 1
		elif sum(l) == len(l) and t == 'wrong':
			WEAK = 1
	if INVALID:
		print('INVALID')
	elif WEAK:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	res = 'FINE'
	for __ in range(n):
		(ans, digits) = input().split()
		if res == 'INVALID':
			continue
		if ans == 'correct' and any([x == '0' for x in digits]):
			res = 'INVALID'
		elif ans == 'wrong' and all([x == '1' for x in digits]):
			res = 'WEAK'
	print(res)


for _ in range(int(input())):
	(codes, questions) = list(map(int, input().split()))
	things = []
	for number in range(codes):
		(expected, real) = list(input().split())
		correct = [1] * questions
		correct = ''.join(list(map(str, correct)))
		if expected == 'correct' and real == correct:
			things.append('FINE')
		elif expected == 'wrong' and real != correct:
			things.append('FINE')
		elif expected == 'wrong' and real == correct:
			things.append('WEAK')
		else:
			things.append('INVALID')
	if 'INVALID' in things:
		print('INVALID')
	elif 'WEAK' in things:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(weak, invalid) = (False, False)
	for _ in range(n):
		(s, num) = input().split()
		if s == 'correct' and num.count('0') > 0:
			invalid = True
		elif s == 'wrong':
			if num.count('1') == m:
				weak = True
	if invalid:
		print('INVALID')
	elif weak:
		print('WEAK')
	else:
		print('FINE')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	okay = 'FINE'
	for x in range(n):
		list1 = list(map(str, input().split()))
		check = list1[0]
		sum1 = 0
		for z in list1[1]:
			sum1 += int(z)
		if check == 'correct' and sum1 < m:
			if okay == 'FINE' or okay == 'WEAK':
				okay = 'INVALID'
		elif check == 'wrong' and sum1 == m:
			if okay == 'FINE':
				okay = 'WEAK'
		elif okay != 'INVALID' and okay != 'WEAK':
			okay = 'FINE'
	print(okay)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = 0
	for i in range(x):
		ab = input().split()
		if a == 1:
			continue
		if ab[0][0] == 'c':
			if '0' in ab[1]:
				print('INVALID')
				a = 1
		elif '0' not in ab[1]:
			a = 2
	if a == 0:
		print('FINE')
	elif a == 2:
		print('WEAK')


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input().split())
	ans = 'FINE'
	for i in range(n):
		if a[i][0] == 'correct':
			if '0' in a[i][1]:
				ans = 'INVALID'
		elif a[i][0] == 'wrong' and ans != 'INVALID':
			if '0' not in a[i][1]:
				ans = 'WEAK'
	print(ans)


for t in range(int(input())):
	l = []
	(n, m) = map(int, input().split())
	for x in range(n):
		s = input().split(' ')
		l.append(s)
	flag = 0
	for x in l:
		if x[0] == 'correct':
			if x[1].count('0') > 0:
				flag = 1
		elif x[0] == 'wrong':
			if x[1].count('0') == 0 and flag != 1:
				flag = 2
	if flag == 0:
		print('FINE')
	elif flag == 1:
		print('INVALID')
	elif flag == 2:
		print('WEAK')


for _ in range(int(input())):
	NM = input().split()
	N = int(NM[0])
	M = int(NM[1])
	a = 2
	for i in range(N):
		validM = input().split()
		valid = validM[0]
		string = validM[1]
		if valid == 'correct':
			for j in range(M):
				if string[j] != '1':
					a = 0
					break
		if valid == 'wrong' and a != 0:
			if '0' not in string:
				a = 1
	if a == 2:
		print('FINE')
	elif a == 1:
		print('WEAK')
	else:
		print('INVALID')


t = int(input())
for tc in range(t):
	(n, m) = tuple(map(int, input().split()))
	(inv, wk, crt) = (False, False, False)
	for i in range(n):
		list_m = input().split()
		if list_m[0] == 'correct':
			if '0' not in list_m[1]:
				crt = True
			else:
				inv = True
		elif list_m[0] == 'wrong':
			if '0' not in list_m[1]:
				wk = True
	if inv:
		print('INVALID')
	elif wk:
		print('WEAK')
	else:
		print('FINE')


t = int(input())
for _ in range(t):
	(n, m) = tuple(map(int, input().split()))
	inv = False
	wek = False
	for test in range(n):
		(a, b) = input().split()
		if a == 'correct':
			if '0' in b:
				inv = True
		elif a == 'wrong':
			if '0' not in b:
				wek = True
	if inv:
		print('INVALID')
	elif wek:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ans = 1
	for i in range(n):
		(s, a) = input().split()
		if s == 'correct':
			if (pow(10, m) - 1) // 9 - int(a) != 0:
				ans *= 0
		elif (pow(10, m) - 1) // 9 - int(a) == 0:
			ans *= 2
	if ans == 1:
		print('FINE')
	elif ans == 0:
		print('INVALID')
	else:
		print('WEAK')


T = int(input())
for i in range(T):
	(Ns, Mt) = tuple(map(int, input().split()))
	k = 1
	for i in range(Ns):
		l = input().split()
		ans = l[0]
		l1 = list(map(int, l[1].strip()))
		l1.sort()
		if ans == 'correct' and l1[0] == 1 or (ans == 'wrong' and l1[0] == 0):
			k *= 1
		elif ans == 'correct' and l1[0] == 0:
			k *= 0
		elif ans == 'wrong' and l1[0] == 1:
			k *= 2
	if k == 1:
		print('FINE')
	elif k == 0:
		print('INVALID')
	else:
		print('WEAK')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = 1
	d = 1
	for __ in range(a):
		(x, y) = map(str, input().split())
		if x == 'correct' and '0' in y:
			c = 0
		elif x == 'wrong' and '0' not in y:
			d = 0
	if not c:
		print('INVALID')
	elif not d:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	flag_invalid = False
	flag_weak = False
	for i in range(n):
		(test, string) = map(str, input().split())
		if test == 'correct' and '0' in string:
			flag_invalid = True
		if test == 'wrong' and '0' not in string:
			flag_weak = True
	if flag_invalid:
		print('INVALID')
	elif flag_weak:
		print('WEAK')
	else:
		print('FINE')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	flag = 0
	count = 0
	for i in range(n):
		(l, k) = map(str, input().split())
		if l == 'correct' and k.count('1') < m:
			flag = 2
		elif l == 'wrong' and k.count('1') == m:
			count = 2
		else:
			pass
	if flag == 0 and count == 2:
		print('WEAK')
	elif flag == 2:
		print('INVALID')
	else:
		print('FINE')


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	out = 'FINE'
	for _ in range(n):
		(a, b) = input().split()
		x = set(b)
		if a == 'correct':
			if x != {'1'}:
				out = 'INVALID'
		elif x == {'1'}:
			out = 'WEAK' if out != 'INVALID' else out
	print(out)


for _ in range(int(input())):
	(N, M) = list(map(int, input().split()))
	c = ''
	for i in range(N):
		x = list(input().split())
		if c != 'INVALID':
			if x[0] == 'correct' and x[1].find('0') != -1:
				c = 'INVALID'
			if x[0] == 'wrong' and x[1].find('0') == -1:
				c = 'WEAK'
	if c == '':
		print('FINE')
	else:
		print(c)


T = int(input())
for i in range(T):
	(N, M) = map(int, input().split())
	test = 'FINE'
	flag = False
	for j in range(N):
		[res, sys] = input().split()
		if res == 'correct':
			if '0' in sys:
				test = 'INVALID'
				flag = True
		elif not flag:
			if '0' not in sys:
				test = 'WEAK'
	print(test)


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	(inv, weak) = ('', '')
	for i in range(N):
		A = input().split()
		if A[0] == 'correct' and A[1].count('1') != M:
			inv = 'i'
		elif A[0] == 'wrong' and A[1].count('1') == M:
			weak = 'w'
	if inv == 'i':
		print('INVALID')
	elif weak == 'w':
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	invalid = 0
	fine = 0
	weak = 0
	for i in range(n):
		(s1, s2) = map(str, input().split())
		for j in range(m):
			if s1 == 'correct' and s2.count('0') != 0:
				invalid = 1
			elif s1 == 'wrong' and s2.count('0') == 0:
				weak = 1
	if invalid == 1:
		print('INVALID')
	elif weak == 1:
		print('WEAK')
	else:
		print('FINE')


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	invalid = False
	weak = False
	for i in range(m):
		(c, s) = map(str, input().split())
		if c == 'correct' and s != '1' * n:
			invalid = True
		if c == 'wrong' and '0' not in s:
			weak = True
	if invalid:
		print('INVALID')
		continue
	if weak:
		print('WEAK')
		continue
	print('FINE')


inp = input()
num_cases = int(inp)
for i in range(num_cases):
	inp = input()
	inp = inp.split(' ')
	n = int(inp[0])
	m = int(inp[1])
	result = ''
	for j in range(n):
		inp = input()
		inp = inp.split(' ')
		solution_tag = inp[0]
		test_results_string = inp[1]
		if solution_tag == 'correct':
			if test_results_string == '1' * m:
				pass
			else:
				result = 'INVALID'
		elif solution_tag == 'wrong':
			if test_results_string == '1' * m:
				if result is not 'INVALID':
					result = 'WEAK'
			else:
				pass
	if result == '':
		result = 'FINE'
	print(result)


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
msg = ['INVALID', 'WEAK', 'FINE']
for _ in range(get_int()):
	(N, M) = get_mint()
	status = 2
	for _ in range(N):
		test = input().split()
		results = set(test[1])
		if test[0] == 'correct':
			if '0' in results:
				status = min(0, status)
		elif '0' not in results:
			status = min(1, status)
	print(msg[status])


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
k = ['INVALID', 'WEAK', 'FINE']
for _ in range(get_int()):
	(v, m) = get_mint()
	status = 2
	for _ in range(v):
		test = input().split()
		results = set(test[1])
		if test[0] == 'correct':
			if '0' in results:
				status = min(0, status)
		elif '0' not in results:
			status = min(1, status)
	print(k[status])


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
msg = ['INVALID', 'WEAK', 'FINE']
for _ in range(get_int()):
	(N, M) = get_mint()
	status = 2
	for _ in range(N):
		test = input().split()
		if test[0] == 'correct' and test[1].count('0') > 0:
			status = min(0, status)
		elif test[0] == 'wrong' and test[1].count('0') == 0:
			status = min(1, status)
	print(msg[status])


t = input()
for c in range(0, int(t)):
	s = list(map(int, input().split()))
	(n, m) = (s[0], s[1])
	result = []
	for _ in range(n):
		l1 = list(input().split())
		if l1[0] == 'correct':
			if all((spot == '1' for spot in l1[1])):
				result.append('F')
			else:
				result.append('I')
		elif l1[0] == 'wrong':
			if any((spot == '0' for spot in l1[1])):
				result.append('F')
			else:
				result.append('W')
	if all((spot == 'F' for spot in result)):
		print('FINE')
	elif any((spot == 'I' for spot in result)):
		print('INVALID')
	else:
		print('WEAK')


for _ in range(int(input())):
	s_t = list(map(int, input().split()))
	(s, t) = (s_t[0], s_t[1])
	result = []
	for _ in range(s):
		soultion_list = list(input().split())
		if soultion_list[0] == 'correct':
			if all((spot == '1' for spot in soultion_list[1])):
				result.append('F')
			else:
				result.append('I')
		elif soultion_list[0] == 'wrong':
			if any((spot == '0' for spot in soultion_list[1])):
				result.append('F')
			else:
				result.append('W')
	if all((spot == 'F' for spot in result)):
		print('FINE')
	elif any((spot == 'I' for spot in result)):
		print('INVALID')
	else:
		print('WEAK')


t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	r = a
	if a > 1 and b > 1:
		e = 0
		f = 0
		m = 0
		k = '1' * b
		for j in range(a):
			(c, d) = map(str, input().split())
			if d == k and c.lower() == 'wrong':
				e = 1
			elif d != k and c.lower() == 'correct':
				f = 1
				q = f
			else:
				m = 0
		if e == 1 and f == 0:
			print('WEAK')
		elif f == 1 or (e == 1 and f == 1):
			print('INVALID')
		else:
			print('FINE')
	else:
		print('INVALID')
	t = t - 1


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	l1 = []
	l2 = []
	for i in range(n):
		s = input().split()
		if s[0] == 'correct':
			if '0' in s[1]:
				l1 = l1 + ['0']
			else:
				l1 = l1 + ['1']
		elif '0' in s[1]:
			l2 = l2 + ['0']
		else:
			l2 = l2 + ['1']
	if '0' in l1:
		print('INVALID')
	elif '1' in l2:
		print('WEAK')
	else:
		print('FINE')


t = int(input())
for i in range(t):
	(N, M) = input().split()
	N = int(N)
	M = int(M)
	res = []
	for i in range(N):
		(S, T) = input().split()
		if S == 'correct':
			if '0' in T:
				res.append(-1)
			else:
				res.append(1)
		elif '0' in T:
			res.append(1)
		else:
			res.append(0)
	if -1 in res:
		print('INVALID')
	elif -1 not in res and 0 in res:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	res = 'fine'
	for i in range(n):
		(check, tests) = input().split()
		if check == 'correct':
			if tests == '0' * m and res == 'fine':
				res = 'weak'
			elif '0' in tests:
				res = 'invalid'
			else:
				pass
		elif tests == '1' * m and res == 'fine':
			res = 'weak'
	print(res.upper())


for i in range(0, int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	(f1, f2) = (0, 0)
	for i in range(0, n):
		(status, case) = input().split()
		if status == 'correct' and '0' in case:
			f1 = 1
		if status == 'wrong' and '0' not in case:
			f2 = 1
	if f1:
		print('INVALID')
	elif f2:
		print('WEAK')
	else:
		print('FINE')


for i in range(int(input())):
	(m, n) = map(int, input().split())
	sol = 'FINE'
	for j in range(m):
		st = input().split()
		cas = st[0]
		an = st[1]
		if cas == 'correct':
			if an.count('0') > 0:
				sol = 'INVALID'
		if cas == 'wrong':
			if an.count('1') == n:
				if sol != 'INVALID':
					sol = 'WEAK'
	print(sol)


for i in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	b = 0
	flag = 0
	for i in range(n):
		(x, s) = input().split()
		if x == 'correct':
			if '0' in s:
				b = 1
		elif '0' not in s:
			flag = 1
	if b:
		print('INVALID')
	elif flag:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	w = []
	c = []
	for _ in range(a):
		(x, y) = input().split()
		if x == 'correct':
			c.append(len(set(y)))
		else:
			w.append(len(set(y)))
	if 2 in c:
		print('INVALID')
	elif 1 in w:
		print('WEAK')
	else:
		print('FINE')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = []
	w = []
	lis = []
	for __ in range(n):
		(s0, s1) = map(str, input().split())
		if s0 == 'correct':
			c.append(len(set(s1)))
		else:
			w.append(len(set(s1)))
	if 2 in c:
		print('INVALID')
	elif 1 in w:
		print('WEAK')
	else:
		print('FINE')