#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> p;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      p.push_back(a);
    }
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      int num = i;
      while (num != i || cnt == 0) {
        cnt++;
        num = p[num] - 1;
      }
      cout << cnt << " ";
    }
    cout << endl;
  }
  return 0;
}
