#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n, ara[209];
    vector<int> vi;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> ara[i];
    for (int i = 1; i <= n; i++) {
      if (ara[i] == i)
        vi.push_back(1);
      else {
        int ctn = 0, mid = ara[i];
        while (1) {
          ctn++;
          mid = ara[mid];
          if (mid == ara[i]) break;
        }
        vi.push_back(ctn);
      }
    }
    for (int i = 0; i < n; i++) cout << vi[i] << " ";
    cout << endl;
  }
  return 0;
}
