#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int ar[n];
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
      --ar[i];
    }
    for (int i = 0; i < n; i++) {
      int pos = i, j = i, cnt = 1, kaku = ar[i];
      while (kaku != pos) {
        j = ar[j];
        kaku = ar[j];
        cnt++;
      }
      cout << cnt << " ";
    }
    cout << endl;
  }
  return 0;
}
