#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  for (T c; b; c = b, b = a % b, a = c)
    ;
  return a;
}
template <typename T>
T lcm(T a, T b) {
  return a * b / (gcd(a, b));
}
const int inf = 0x3f3f3f3f;
const long long infl = 0x3f3f3f3f3f3f3f3fLL;
template <typename T>
void rd(T &a) {
  T ch, ng = 0;
  for (; ((ch = getchar()) < '0' || ch > '9') && ch != '-';)
    ;
  ng = (ch == '-'), a = ng ? 0 : (ch ^ '0');
  for (; (ch = getchar()) >= '0' && ch <= '9';) a = (a * 10) + (ch ^ '0');
  if (ng) a = ~a + 1;
}
template <typename T>
void wrt(T a) {
  T bf[20], st = 0;
  if (!a) putchar('0');
  if (a < 0) putchar('-'), a = ~a + 1;
  for (; a; bf[st++] = a % 10, a /= 10)
    ;
  for (; st--; putchar(bf[st] ^ '0'))
    ;
}
const int maxn = 1e6 + 5, maxh = 20;
int q, p[maxn][maxh], h[maxn], b = 2, e = 3, n = 4, res = 2;
void upd(int u) {
  h[++n] = h[u] + 1, p[n][0] = u;
  for (int(i) = (1), _b = (maxh - 1); (i) <= _b; ++(i))
    p[n][i] = p[p[n][i - 1]][i - 1];
  h[++n] = h[u] + 1, p[n][0] = u;
  for (int(i) = (1), _b = (maxh - 1); (i) <= _b; ++(i))
    p[n][i] = p[p[n][i - 1]][i - 1];
}
int lca(int u, int v) {
  if (h[u] < h[v]) u ^= v ^= u ^= v;
  int k = h[u] - h[v];
  for (int i = 0; k; k >>= 1, ++i)
    if (k & 1) u = p[u][i];
  if (u == v) return u;
  for (int(i) = (maxh - 1), _b = (0); (i) >= _b; --(i))
    if (p[u][i] != p[v][i]) u = p[u][i], v = p[v][i];
  return p[v][0];
}
void query() {
  int c1 = h[n] + h[b] - (h[lca(n, b)] << 1),
      c2 = h[n] + h[e] - (h[lca(n, e)] << 1);
  if (res < c1) e = n, res = c1;
  if (res < c2) b = n, res = c2;
  wrt(res), putchar('\n');
}
int main() {
  rd(q);
  for (int(i) = (2), _b = (4); (i) <= _b; ++(i)) p[i][0] = 1, h[i] = 1;
  int u;
  for (; q--;) rd(u), upd(u), query();
}
