#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b) {
  long long pow = 1;
  for (int i = 0; i < b; i++) pow *= a;
  return pow;
}
long long returnnumber(map<long long, long long> a, long long b) {
  return a[b];
}
void fast() {
  cin.tie(0);
  cin.sync_with_stdio(0);
}
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long primes(long long n) {
  long long prime = 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      prime++;
    }
  }
  return prime;
}
int main() {
  fast();
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    map<long long, long long> freq;
    int c[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
      freq[i + 1] = c[i];
    }
    for (int i = 0; i < n; i++) {
      int temp = freq[i + 1];
      int counter = 1;
      while (temp != i + 1) {
        temp = freq[temp];
        counter++;
      }
      cout << counter << " ";
    }
    cout << "\n";
    ;
  }
}
