#include <iostream>
#include <cmath>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n; cin>>n;
    rep(i,n){
        cout << "Case " << i+1 << ":" << endl;
        int a; cin >> a;
        rep(j,10){
            a*=a;
            a/=100;
            a = a-a/10000*10000;
            cout << a << endl;
        }
    }
}
 