#include <bits/stdc++.h>
int main() {
  int q;
  std::cin >> q;
  std::vector<int> V;
  for (int i = 0; i < q; ++i) {
    int n;
    std::cin >> n;
    std::vector<int> v1;
    std::vector<int> v2(n);
    for (int j = 0; j < n; ++j) {
      std::cin >> v2[j];
      v1.push_back(j + 1);
    }
    for (int k = 0; k < v1.size(); ++k) {
      int count = 1;
      int num = k;
      while (v1[k] != v2[num]) {
        num = v2[num] - 1;
        ++count;
      }
      V.push_back(count);
    }
    V.push_back(0);
  }
  for (int i = 0; i < V.size(); ++i) {
    if (V[i] == 0)
      std::cout << "\n";
    else {
      std::cout << V[i] << " ";
    }
  }
}
