#include <vector>
#include <algorithm>
#include <iostream>
#include <stdint.h>
#include <string>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <cassert>
 
using namespace std;
 
uint32_t a[1001];
bool m[1001];
 
void Solve(int32_t t) {
	uint32_t n;
 
	memset(a, 0, sizeof(a));
	memset(m, 0, sizeof(m));
	cin >> n;
 
	double c = 0.0;
 
	for (uint32_t i = 1; i <= n; i++) {
		cin >> a[i];
	}
 
	for (uint32_t i = 1; i <= n; i++) {
		if (a[i] == i || m[i]) {
			m[i] = true;
			continue;
		}
		else {
			uint32_t q = 0;
			uint32_t j = i;
			do {
				q++;
				m[j] = true;
				j = a[j];
			} while (j != i);		
			c += (q - 1) * 2;
		}
	}
 
	cout << "Case #" << t << ": " << c <<endl;
}
 
int main() {
	int32_t t;
	cin >> t;
 
	for (int32_t i = 1; i <= t; i++) {
		Solve(i);
	}
 
	return 0;
}