#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, x;
    cin >> n;
    long long p[n], a[n];
    long long ans[n];
    for (i = 1; i <= n; i++) {
      cin >> p[i];
      ans[i] = 1;
    }
    for (i = 1; i <= n; i++) {
      j = p[i];
      while (j != i) {
        j = p[j];
        ans[i]++;
      }
    }
    for (i = 1; i <= n; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
