#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long N = 1e5;
long long p[2 * N + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long casos;
  cin >> casos;
  while (casos--) {
    long long n;
    cin >> n;
    vector<long long> v;
    v.push_back(0);
    for (int i = 0; i < n; i++) {
      long long num;
      cin >> num;
      v.push_back(num);
    }
    for (int i = 1; i <= n; i++) {
      p[i] = v[i];
    }
    for (int i = 1; i <= n; i++) {
      long long cont = 0;
      long long b = 0;
      long long j = i;
      if (i == v[i]) {
        cout << "1 ";
        continue;
      }
      while (i != b) {
        b = p[v[j]];
        j = v[j];
        cont++;
      }
      cout << cont + 1 << " ";
    }
    cout << endl;
  }
}
