Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		seed, _ := strconv.Atoi(scanner.Text())
		fmt.Printf("Case %d:\n", i+1)
		for j := 0; j < 10; j++ {
			tmp := fmt.Sprintf("%08d", seed*seed)
			seed, _ = strconv.Atoi(tmp[2:6])
			fmt.Println(seed)
		}
	}
}

C++: #include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int solve(int n) {
    int p = int(pow(n, 2));
    p /= 100;
    int res = 0, t = 1;
    for (int i = 0; i < 4; i++) {
        res += t * (p % 10);
        p /= 10;
        t*=10;
    }
    return res;
}

int main()
{
    int T, n;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++) {
        scanf("%d", &n);
        printf("Case %d:\n", t);
        for (int i = 0; i < 10; i++) {
            n = solve(n);
            printf("%d\n", n);
        }
    }
}

C++: #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>

using namespace std;

int main(){
  int n;
  scanf("%d", &n);

  for(int i=0;i<n;i++){
    printf("Case %d:\n", i+1);

    int k;
    char s[256];
    scanf("%d", &k);

    for(int j=0;j<10;j++){
      k *= k;
      sprintf(s, "%08d", k);
      int l = strlen(s);
      string sn(s);
      k = atoi(sn.substr(l-6, 4).c_str());
      printf("%d\n", k);
    }
  }
}

C++: #include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(){
	int N;
	cin >> N;
	for(int i=1;i<=N;i++){
		int s;
		cin >> s;
		cout << "Case " << i << ":" << endl;
		for(int j=0;j<10;j++){
			s *= s;
			stringstream ss;
			ss << s;
			string r = ss.str();
			//cout << r << endl;
			//rª3¢ÌêC^ñÌÍ¢ÂàO
			if(r.size()<3){s = 0;continue;}
			//(n>5)?4:n-2;
			//(n>5)?n-6:0;
			int dig = (r.size()>5)?4:r.size()-2, pos = (r.size()>5)?r.size()-6:0;
			ss.str("");
			ss << r.substr(pos,dig);
			ss >> s;
			cout << s << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		cout<<"Case "<<i+1<<":"<<endl;
		int a;
		cin>>a;
		rep(j,10){
			a*=a;
			stringstream ss;
			ss<<a;
			string s;
			ss>>s;
			while(s.size()<8){
				s="0"+s;
			}
			s=s.substr(2,4);
			stringstream ss1;
			ss1<<s;
			ss1>>a;
			cout<<a<<endl;
		}

	}
}

C++: #include <iostream>
using namespace std;

int main(void)
{
  int i,j,n,h;
  cin >> n;
  for (i=1; i<=n; i++);{
    cin >> h;
  
    cout << "Case " << i << ":" << endl;

    for (j=1; j<=10; j++)
      { h=h*h;
        h=h/100;
        h=h%10000;
        cout << h << endl;}
  }

    return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int d; cin >> d;
	rep(i, 0, d) {
		cout << "Case " << i << ":" << endl;
		int s; cin >> s;
		rep(j, 0, 10) {
			s *= s;
			s %= 1000000;
			s /= 100;
			cout << s << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;

int main(void){
	int n,m;
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>n;
		cout<<"case "<<i<<":"<<endl;
		for(int j=0;j<10;j++){
			n=n*n;
			n=((n%1000000)/100);
			cout<<n<<endl;
		}
	}
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int d; cin >> d;
	rep(i, 0, d) {
		cout << "Case " << i + 1 << ":" << endl;
		int s; cin >> s;
		rep(j, 0, 10) {
			s *= s;
			s %= 1000000;
			s /= 100;
			cout << s << endl;
		}
	}
	return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  int n, s;

  cin >> n;
  REP(i, n) {
    cout << "Case " << i+1 << ':' << endl;
    cin >> s;
    REP(j, 10) {
      s = s*s;
      s = (s%1000000) / 100;
      cout << s << endl;
    }
  } 
}