#include <bits/stdc++.h>
int main() {
  int tst;
  std ::cin >> tst;
  while (tst--) {
    int n;
    std ::cin >> n;
    int arr[n + 1];
    for (int i = 1; i <= n; i++) std ::cin >> arr[i];
    std ::vector<int> vecRes;
    for (int i = 1; i <= n; i++) {
      int res = 1;
      int j = arr[i];
      for (; j != i; j = arr[j]) res++;
      vecRes.push_back(res);
    }
    std ::cout << vecRes.at(0);
    for (int i = 1; i < vecRes.size(); i++) std ::cout << ' ' << vecRes.at(i);
    std ::cout << '\n';
  }
}
