#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, inftar = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10, mlg = 23, sq = 450;
int h[maxn];
int anc[maxn][mlg];
int go_up(int u, int h) {
  for (int i = mlg - 1; i >= 0; i--) {
    if (h & (1 << i)) {
      u = anc[u][i];
    }
  }
  return u;
}
int lca(int u, int v) {
  if (h[u] < h[v]) {
    swap(u, v);
  }
  int tmph = h[u] - h[v];
  u = go_up(u, tmph);
  for (int i = mlg - 1; i >= 0; i--) {
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  }
  if (u != v) {
    return anc[u][0];
  } else {
    return u;
  }
}
int dist(int u, int v) {
  int lc = lca(u, v);
  return h[u] - h[lc] + h[v] - h[lc];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int q;
  scanf("%i", &q);
  int diam = 2;
  int v1 = 2;
  int v2 = 3;
  int n = 4;
  h[1] = 0;
  h[2] = h[3] = h[4] = 1;
  anc[1][0] = anc[2][0] = anc[3][0] = anc[4][0] = 1;
  for (int i = 1; i < mlg; i++) {
    anc[1][i] = anc[anc[1][i - 1]][i - 1];
    anc[2][i] = anc[anc[2][i - 1]][i - 1];
    anc[3][i] = anc[anc[3][i - 1]][i - 1];
    anc[4][i] = anc[anc[4][i - 1]][i - 1];
  }
  while (q--) {
    int v;
    scanf("%i", &v);
    n += 2;
    h[n - 1] = h[n] = h[v] + 1;
    anc[n - 1][0] = v;
    anc[n][0] = v;
    for (int i = 1; i < mlg; i++) {
      anc[n][i] = anc[anc[n][i - 1]][i - 1];
      anc[n - 1][i] = anc[anc[n][i - 1]][i - 1];
    }
    if (dist(n, v1) > diam) {
      v2 = n;
      diam = dist(n, v1);
    }
    if (dist(n, v2) > diam) {
      v1 = n;
      diam = dist(n, v2);
    }
    printf("%i\n", diam);
  }
}
