#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int n; cin >> n;

    rep(k,n)
    {
        int r;
        cout << "Case " << k+1 << ":" << endl;
        cin >> r;

        REP(10)
        {
            r = ((r * r) %(1000*1000))/100;
            cout << r << endl;
        }

    }

    return 0;
}