#include <bits/stdc++.h>
using namespace std::chrono;
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int a[n], b[n], ans[n], cur, day = 1;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      b[i] = a[i];
    }
    for (int i = 0; i < n; ++i) {
      day = 1;
      cur = i;
      while (day++) {
        if (b[i] == cur + 1) {
          ans[i] = day;
          day = 1;
          break;
        } else {
          i = b[i] - 1;
        }
      }
      i = cur;
    }
    for (int i = 0; i < n; ++i) {
      cout << ans[i] - 1 << " ";
    }
    cout << endl;
  }
}
