#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
                 long long mod = (long long)(1e9 + 7)) {
  if (!b) return 1;
  a %= mod;
  return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn = 1e6 + 4, mxk = 20;
int n, q;
int d[mxn], parent[mxn][mxk];
void add(int i, int p) {
  parent[i][0] = p;
  d[i] = d[p] + 1;
  for (int j = 0; j < mxk; j++)
    if (j) parent[i][j] = parent[parent[i][j - 1]][j - 1];
}
int lca(int i, int j) {
  if (d[i] > d[j]) swap(i, j);
  int diff = d[j] - d[i];
  for (int k = mxk - 1; k >= 0; k--)
    if (diff & (1 << k)) j = parent[j][k];
  if (i == j) return i;
  for (int k = mxk - 1; k >= 0; k--)
    if (parent[i][k] != parent[j][k]) i = parent[i][k], j = parent[j][k];
  return parent[i][0];
}
int dist(int i, int j) { return d[i] + d[j] - 2 * d[lca(i, j)]; }
void solve() {
  for (int j = 0; j < mxk; j++) parent[0][j] = 0;
  d[0] = 0;
  add(1, 0);
  add(2, 0);
  add(3, 0);
  scanf("%d", &q);
  n = 4;
  stringstream ss;
  int a = 1, b = 2;
  int best = dist(a, b);
  for (int _ = 0; _ < q; _++) {
    int x;
    scanf("%d", &x);
    x--;
    add(n++, x);
    add(n++, x);
    int d1 = dist(a, n - 1), d2 = dist(b, n - 1);
    if (max(d1, d2) > best) {
      best = max(d1, d2);
      if (d1 > d2)
        b = n - 1;
      else
        a = n - 1;
    }
    ss << best << endl;
  }
  cout << ss.str();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
