#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n, x;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    vector<int> p;
    for (int j = 0; j < n; j++) {
      cin >> x;
      p.push_back(x);
    }
    for (int j = 0; j < n; j++) {
      int t = 1;
      int l;
      int k = p[j];
      while (k != j + 1) {
        l = p[k - 1];
        k = l;
        t++;
      }
      cout << t << " ";
    }
    cout << "\n";
  }
  return 0;
}
