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