#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n;
  cin >> q;
  while (q--) {
    cin >> n;
    vector<int> original;
    int temp;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      original.push_back(temp);
    }
    for (int i = 0; i < original.size(); i++) {
      int days = 0;
      int origpos = i;
      int newpos = original[i];
      bool home = false;
      while (!home) {
        newpos = original[newpos - 1];
        if (newpos == original[i]) {
          home = true;
        }
        days++;
      }
      cout << days << " ";
    }
    cout << endl;
  }
}
