#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int j = 0; j < q; j++) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < n; i++) {
      int c = 1;
      int k = i;
      while (v[k] != i + 1) {
        c++;
        k = v[k] - 1;
      }
      ans[i] = c;
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
}
