#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 100001;
const double eps = 1e-6;
const double pi = acos(-1);
void code();
void File();
int main() {
  code();
  File();
  int n, Sum, j, g;
  int t = 0;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 0; i < n; i++) cin >> a[i + 1];
    bool Ok;
    for (int i = 0; i < n; i++) {
      i++;
      Ok = 1;
      Sum = 0, j = i, g = i;
      while (Ok) {
        if (a[j] == i) Ok = 0;
        j = a[g];
        g = a[g];
        Sum++;
      }
      i--;
      cout << Sum << " ";
    }
    cout << "\n";
  }
}
void code() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(2);
}
void File() {}
