# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
def CheckDotAndAt(stringIN):
length = len(str(stringIN))
for i in range(length):
if (i > 0) & (i + 1 < length):
if ((stringIN[i] == '@') | (stringIN[i] == '.')) & ((stringIN[i + 1] == '@') | (stringIN[i-1] == '@') | (stringIN[i + 1] == '.') | (stringIN[i-1] == '.')):
return False
elif (stringIN[i] == '@') | (stringIN[i] == '.'):
return False
return True
def CheckSpelling(stringIN):
for i in range(len(str(stringIN))):
value = ord(stringIN[i])
if ((ord('a') <= value <= ord('z')) | (ord('A') <= value <= ord('Z')) | (ord('0') <= value <= ord('9')) | (value == ord('@')) | (value == ord('_')) | (value == ord('.'))) == False:
return False
return True
def CheckLastThreeChar(stringIN):
max = len(str(stringIN))
start = max - 4
count = 0
startCounting = False
for i in range(start, max):
if(startCounting == True):
if(stringIN[i] != '.'):
count += 1
else:
return False
elif(stringIN[i] == '.'):
startCounting = True
count = 0
if(1 < count < 4):
return True
return False
def CheckSpellingOfLastThreeChar(stringIN):
max = len(str(stringIN))
start = max - 3
for i in range(start, max):
value = ord(stringIN[i])
if((ord('a') <= value <= ord('z')) | (ord('A') <= value <= ord('Z')) | (value == ord('.'))) == False:
return False
return True
def MonkeyCounter(stringIN):
count = 0
for i in range(len(stringIN)):
if stringIN[i] == '@':
count += 1
return count
def FirstWordSize(stringIN):
count = 0
for i in range(len(stringIN)):
if (stringIN[i] == '@'):
return count
count += 1
return count
minLen = 4
n = int(raw_input())
for i in range(n):
stringIN = str(raw_input())
strLen = len(stringIN)
if(strLen <= 4):
print 'Nie'
elif(FirstWordSize(stringIN) <= 20) & (CheckDotAndAt(stringIN) == True) & (CheckLastThreeChar(stringIN) == True) & (CheckSpelling(stringIN) == True) & (MonkeyCounter(stringIN) == 1) & (CheckSpellingOfLastThreeChar(stringIN) == True):
print 'Tak'
#print 'FWS {0} CDAT {1} CLTC {2} CS {3} MK {4} CSOLTC {5}'.format(FirstWordSize(stringIN), CheckDotAndAt(stringIN), CheckLastThreeChar(stringIN), CheckSpelling(stringIN), MonkeyCounter(stringIN), CheckSpellingOfLastThreeChar(stringIN))
else:
print 'Nie'
#print 'FWS {0} CDAT {1} CLTC {2} CS {3} MK {4} CSOLTC {5}'.format(FirstWordSize(stringIN), CheckDotAndAt(stringIN), CheckLastThreeChar(stringIN), CheckSpelling(stringIN), MonkeyCounter(stringIN), CheckSpellingOfLastThreeChar(stringIN))