#include <bits/stdc++.h>
using namespace std;
int index(int i, int a[]) {
  int dem = 1;
  int temp = i - 1;
  while (i != a[temp]) {
    dem++;
    temp = a[temp] - 1;
  }
  return dem;
}
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a[200];
    int n;
    cin >> n;
    for (int j = 0; j < n; j++) cin >> a[j];
    for (int j = 1; j <= n; j++) cout << index(j, a) << " ";
    cout << "\n";
  }
  return 0;
}
