#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y, z, bz[1100001][25], d[1100001], g;
int ask(int X, int Y) {
  int res = d[X] + d[Y];
  if (d[X] < d[Y]) swap(X, Y);
  for (int j = 20; j >= 0; j--)
    if (d[bz[X][j]] > d[Y]) X = bz[X][j];
  if (d[X] != d[Y]) X = bz[X][0];
  for (int j = 20; j >= 0; j--)
    if (bz[X][j] != bz[Y][j]) X = bz[X][j], Y = bz[Y][j];
  if (X != Y) X = bz[X][0];
  return res - d[X] * 2;
}
int main() {
  scanf("%d", &m);
  x = 2, y = 3, z = 2;
  n = 4;
  d[1] = 1;
  d[2] = d[3] = d[4] = 2;
  bz[2][0] = bz[3][0] = bz[4][0] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &k);
    bz[++n][0] = k;
    d[n] = d[k] + 1;
    bz[++n][0] = k;
    d[n] = d[k] + 1;
  }
  for (int i = 1; i <= 20; i++)
    for (int j = 1; j <= n; j++) bz[j][i] = bz[bz[j][i - 1]][i - 1];
  for (int i = 5; i <= n; i += 2) {
    k = ask(i, x);
    g = ask(i, y);
    if (k >= g && k >= z)
      z = k, y = i;
    else if (g >= k && g >= z)
      z = g, x = i;
    printf("%d\n", z);
  }
}
