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 <iostream>
using namespace std;

int main(){
  int i,N;
  char suji[9];
  int n; cin >> N;
  int cnt = 1;
  while( N > 0 ){
    N--;
    cin >> n;
    int k = 10;
    cout << "Case" << " " << cnt << ":" << endl;
    cnt++;
    while( k > 0 ){
      k--;
      int s = n*n;
      for( i = 1; i <= 8; i++ ) suji[i] = '0'; 

      int amari_zan = 10,wari_zan = 1,tmp;
      for( i = 8; i >= 1; i-- ){
	tmp = s % amari_zan;
	tmp /= wari_zan;
	suji[i] = tmp + '0';
	amari_zan *= 10;
	wari_zan *= 10;
      }
      int kakeru = 1000;
      n = 0;
      for( i = 3; i <= 6; i++ ){
	n += ( suji[i] - '0' )  * kakeru;
	kakeru /= 10;
      }

      cout << n << endl;
    }
  }
  return 0;
}

C++: #include <sstream>
#include <iostream>
#include <cstdio>

using namespace std;

int dataset,aiju;

int main(int argc,char **argv){
  cin >> dataset;
  for(int rupu=0;rupu<dataset;rupu++)
    {
      printf("Case %d:",++aiju); cout << endl;
      int s;
      cin >> s;
      for(int itiToJuu=0;itiToJuu<10;itiToJuu++)
	{
	  s = s * s;
	  stringstream ss;
	  ss << s;
	  string sutoring;
	  ss >> sutoring;

	  s = 0;
	  int leading_zero = 114;
	  int nanikadasita = 194;
	  for(int aaa=(int)sutoring.size()-6;aaa<(int)sutoring.size()-2;aaa++)
	    {
	      if( aaa < 0 )
		{
		  continue;
		}
	      else 
		{
		  s = s * 10;
		  s = s + sutoring[aaa] - '0';
		  if( sutoring[aaa] != '0' ) leading_zero = 514;
		  if(leading_zero == 114 && sutoring[aaa] == '0' ) 
		    {

		    }
		  else
		    {
		      nanikadasita = 11111;
		      cout << sutoring[aaa];
		    }
		}
	    }
	  if( nanikadasita == 194 ) cout << 0;
	  cout << endl;
	}
    }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cout << "Case 1:" << endl;
		for (int j = 0; j < 10; j++) {
			string s;
			x *= x;
			string t = to_string(x);
			for (int k = 0; k < 8 - t.length(); k++) {
				s += '0';
			}
			s += t;
			x = stoi(s.substr(2, 4));
			cout << x << endl;

		}
	}
	return 0;
}