#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n,x;
    double output;
    while(cin >> n){
        rep(i,n){
            cout << "Case " << i + 1 << ":" << endl;
            cin >> x;
            rep(j,10){
                x *= x;
                while(x >= 1000000)
                    x -= 1000000;
                output = static_cast<double>(x) / 100;
                cout << static_cast<int>(output) << endl;
                x = static_cast<int>(output);
            }
        }
    }
}