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