def main():

    d = int(input())

    a = []

    for _ in range(d):

        a.append(int(input()))



    ans = []

    for x in range(d):

        ansans = []

        hoge = a[x]

        for y in range(10):

            hoge = list("{0:08d}".format(hoge ** 2))

            s = ""

            for z in range(2, 6):

                s += hoge[z]

            hoge = int(s)

            ansans.append(hoge)

        ans.append(ansans)



    for x in range(1, d + 1):

        print("Case", x,end= "")

        print(":")

        for y in ans[x - 1]:

            print(y)





if __name__ == "__main__":

    main()

def main():

    d = int(input())

    a = []

    for _ in range(d):

        a.append(int(input()))



    for x in range(len(a)):

        print("Case ",end = "")

        print(x+1, end = "")

        print(":")

        for _ in range(10):

            a[x] = str("{0:08d}".format(a[x] ** 2))

            hoge = ""

            for y in range(2, 6):

                hoge += a[x][y]

            hoge = int(hoge)

            a[x] = hoge

            print(a[x])





if __name__ == "__main__":

    main()

def main():
    d = int(input())
    a = []
    for _ in range(d):
        a.append(int(input()))
    ans = []
    for x in range(d):
        ansans = []
        hoge = a[x]
        for y in range(10):
            hoge = list("{0:08d}".format(hoge**2))
            s = ""
            for z in range(2, 6):
                s += hoge[z]
            hoge = int(s)
            ansans.append(hoge)
        ans.append(ansans)
    for x in range(1, d + 1):
        print("Case", x, end="")
        print(":")
        for y in ans[x - 1]:
            print(y)


if __name__ == "__main__":
    main()

def main():
    d = int(input())
    a = []
    for _ in range(d):
        a.append(int(input()))
    for x in range(len(a)):
        print("Case ", end="")
        print(x + 1, end="")
        print(":")
        for _ in range(10):
            a[x] = str("{0:08d}".format(a[x] ** 2))
            hoge = ""
            for y in range(2, 6):
                hoge += a[x][y]
            hoge = int(hoge)
            a[x] = hoge
            print(a[x])


if __name__ == "__main__":
    main()

-    ans = [] -    for x in range(d): -        ansans = [] -        hoge = a[x] -        for y in range(10): -            hoge = list("{0:08d}".format(hoge**2)) -            s = "" -            for z in range(2, 6): -                s += hoge[z] -            hoge = int(s) -            ansans.append(hoge) -        ans.append(ansans) -    for x in range(1, d + 1): -        print("Case", x, end="") +    for x in range(len(a)): +        print("Case ", end="") +        print(x + 1, end="") -        for y in ans[x - 1]: -            print(y) +        for _ in range(10): +            a[x] = str("{0:08d}".format(a[x] ** 2)) +            hoge = "" +            for y in range(2, 6): +                hoge += a[x][y] +            hoge = int(hoge) +            a[x] = hoge +            print(a[x])