# 틱택토 - BOJ
while True:
s = list(input())
if s[0] == 'e':
break
x, y, cx, cy = 0, 0, 0, 0
for i in range(3):
if (s[i * 3] == 'O' and s[i * 3 + 1] == 'O' and s[i * 3 + 2] == 'O') \
or (s[i] == 'O' and s[i + 3] == 'O' and s[i + 6] == 'O') \
or (s[0] == 'O' and s[4] == 'O' and s[8] == 'O') \
or (s[2] == 'O' and s[4] == 'O' and s[6] == 'O'):
x += 1
elif (s[i * 3] == 'X' and s[i * 3 + 1] == 'X' and s[i * 3 + 2] == 'X') \
or (s[i] == 'X' and s[i + 3] == 'X' and s[i + 6] == 'X') \
or (s[0] == 'X' and s[4] == 'X' and s[8] == 'X') \
or (s[2] == 'X' and s[4] == 'X' and s[6] == 'X'):
y += 1
for j in range(3):
if s[i * 3 + j] == 'O':
cx += 1
if s[i * 3 + j] == 'X':
cy += 1
if cy - cx == 1 and y and x == 0:
print("valid")
elif cx == cy and x and y == 0:
print("valid")
elif cy == 5 and cx == 4 and y == 0 and x == 0:
print("valid")
else:
print("invalid")