<gh_stars>1-10
# https://www.codechef.com/viewsolution/43726792

for _ in range(int(input())):
    a = input()
    print(int(a[0]) + int(a[-1]))
# https://www.codechef.com/viewsolution/43726792

for _ in range(int(input())):
    a = input()
    print(int(a[0]) + int(a[-1]))
# https://www.codechef.com/viewsolution/43726792