#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> arr(n + 2), ans;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    for (int i = 1; i <= n; i++) {
      int j = arr[i];
      int cnt = 1;
      while (j != i) {
        j = arr[j];
        cnt++;
      }
      ans.push_back(cnt);
    }
    for (auto &value : ans) cout << value << " ";
    cout << endl;
  }
  return 0;
}
