#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-11;
double const pi = 3.1415926535;
long long const mod = 1e9 + 7;
int p[205];
void solve() {
  int n;
  cin >> n;
  int pos = 0;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= n; i++) {
    pos = p[i];
    int ans = 1;
    while (pos != i) {
      ans += 1;
      pos = p[pos];
    }
    cout << ans << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) solve();
  return 0;
}
