def function(s):
    if len(s) == 1:
        return s
    else:
        num = 0
        for i in range(len(s)):
            num += int(s[i])
        return function(str(num))


n = int(input())
num = []
for i in range(n):
    num.append(input())
for i in range(n):
    print(function(num[i]))

9b35e4ef8fc4f5e149405daa2aa80c5e15b2441a
<mask token>

def function(s):
    if len(s) == 1:
        return s
    else:
        num = 0
        for i in range(len(s)):
            num += int(s[i])
        return function(str(num))


<mask token>

def function(s):
    if len(s) == 1:
        return s
    else:
        num = 0
        for i in range(len(s)):
            num += int(s[i])
        return function(str(num))


<mask token>
for i in range(n):
    num.append(input())
for i in range(n):
    print(function(num[i]))

def function(s):
    if len(s) == 1:
        return s
    else:
        num = 0
        for i in range(len(s)):
            num += int(s[i])
        return function(str(num))


n = int(input())
num = []
for i in range(n):
    num.append(input())
for i in range(n):
    print(function(num[i]))
