#include <bits/stdc++.h>
using LL = long long;
using ULL = unsigned long long;
int main() {
  using namespace std;
  LL queries = 0;
  cin >> queries;
  while (queries--) {
    LL kids = 0;
    cin >> kids;
    vector<LL> returns;
    while (kids--) {
      LL returnTo = 0;
      cin >> returnTo;
      --returnTo;
      returns.push_back(returnTo);
    }
    for (size_t i = 0; i < returns.size(); ++i) {
      LL start = i;
      LL current = returns[i];
      LL answer = 1;
      while (current != start) {
        current = returns[current];
        ++answer;
      }
      cout << answer << " ";
    }
    cout << endl;
  }
  return 0;
}
