#include <bits/stdc++.h>
using namespace std;
const unsigned long long int mod = 1e9 + 7;
inline unsigned long long int add(unsigned long long int a,
                                  unsigned long long int b) {
  return (a % mod + b % mod) % mod;
}
inline unsigned long long int sub(unsigned long long int a,
                                  unsigned long long int b) {
  return (a % mod - b % mod + mod) % mod;
}
inline unsigned long long int mul(unsigned long long int a,
                                  unsigned long long int b) {
  a %= mod;
  b %= mod;
  return a * b % mod;
}
inline unsigned long long int power(unsigned long long int a,
                                    unsigned long long int b,
                                    unsigned long long int MOD) {
  a %= mod;
  unsigned long long int res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= MOD;
    }
    a = a * a;
    a %= MOD;
    b >>= 1;
  }
  return res;
}
clock_t time_p = clock();
void time() {
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (long double)(time_p) / CLOCKS_PER_SEC << endl;
}
signed main() {
  unsigned long long int t;
  cin >> t;
  while (t--) {
    unsigned long long int n, i, j, x, temp, count = 1;
    vector<unsigned long long int> a, b;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> temp;
      a.push_back(temp);
    }
    for (i = 0; i < n; i++) {
      b = a;
      x = i;
      count = 1;
      while (1) {
        if (b[x] == i + 1)
          break;
        else {
          count++;
          temp = b[x];
          b[x] = b[temp - 1];
          b[temp - 1] = temp;
        }
      }
      cout << count << " ";
    }
    cout << endl;
  }
  return 0;
}
