#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      int days = 1;
      int j = i;
      while (arr[j] - 1 != i) {
        days++;
        j = arr[j] - 1;
      }
      ans.push_back(days);
    }
    for (int i = 0; i < n; i++) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
