#include <bits/stdc++.h>
using namespace std;
bool sortinrevp(const pair<long long, long long> &a,
                const pair<long long, long long> &b) {
  return (a.first > b.first);
}
bool sortinrev(const long long &a, const long long &b) { return (a > b); }
long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long isPrime(long long n) {
  if (n <= 1) return 0;
  for (long long i = 2; i < n; i++)
    if (n % i == 0) return 0;
  return 1;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1];
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  for (long long i = 1; i < n + 1; i++) {
    long long p = 1, j = a[i];
    while (j != i) {
      p++;
      j = a[j];
    }
    cout << p << " ";
  }
  cout << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
