#include <bits/stdc++.h>
using namespace std;
int a[10000];
vector<int> v;
void dfs(int k, int num, int day) {
  if (k == num) {
    v.push_back(day);
    return;
  }
  dfs(k, a[num], day + 1);
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    int f = 0;
    v.clear();
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      dfs(i, a[i], 1);
    }
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    cout << endl;
  }
}
