#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n + 1], c;
    for (long long int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    for (long long int i = 1; i <= n; i++) {
      long long int j = arr[i];
      c = 1;
      while (j != i) {
        j = arr[j];
        c++;
      }
      cout << c << " ";
    }
    cout << endl;
  }
}
