#include <bits/stdc++.h>
using namespace std;
const int LTmaxm = 5100000;
const int LTmaxn = 1100000;
struct line {
  int to, next;
};
struct Link_Table {
  line li[LTmaxm];
  int be_[LTmaxn], l;
  int to(int i) { return li[i].to; }
  int next(int i) { return li[i].next; }
  int be(int i) { return be_[i]; }
  void makeline(int fr, int to) {
    ++l;
    li[l].next = be_[fr];
    be_[fr] = l;
    li[l].to = to;
  }
  void makeline_double(int fr, int to) {
    makeline(fr, to);
    makeline(to, fr);
  }
  void clear() {
    l = 0;
    memset(be_, 0, sizeof(be_));
  }
} L;
const int maxn = 1100000;
int fa[maxn][23], d[maxn], Q, tot, p[maxn], l, r, m;
queue<int> q;
void build() {
  q.push(1);
  d[1] = 1;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 1, k = fa[now][0]; k; k = fa[k][i - 1], ++i)
      fa[now][i] = fa[k][i - 1];
    for (int i = L.be(now); i; i = L.next(i)) {
      int to = L.to(i);
      d[to] = d[now] + 1;
      fa[to][0] = now;
      q.push(to);
    }
  }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  while (d[u] > d[v]) {
    int i;
    for (i = 0; d[u] - (1 << i) >= d[v]; ++i)
      ;
    --i;
    u = fa[u][i];
  }
  while (u != v) {
    int i;
    for (i = 0; fa[u][i] != fa[v][i]; ++i)
      ;
    if (i) --i;
    u = fa[u][i];
    v = fa[v][i];
  }
  return u;
}
int dist(int u, int v) {
  int c = lca(u, v);
  return abs(d[u] - d[c]) + abs(d[v] - d[c]);
}
int mi(int u, int v) { return d[u] > d[v] ? u : v; }
int getp(int u) {
  int c = lca(l, r);
  int ans = c;
  ans = mi(ans, lca(l, u));
  ans = mi(ans, lca(r, u));
  return ans;
}
int main() {
  scanf("%d", &Q);
  L.makeline(1, 2);
  L.makeline(1, 3);
  L.makeline(1, 4);
  tot = 4;
  for (int i = 0; i < Q; ++i) {
    int t = 0;
    scanf("%d", &t);
    L.makeline(t, ++tot);
    L.makeline(t, ++tot);
    p[i] = tot;
  }
  build();
  l = 2, r = 3;
  for (int i = 0; i < Q; ++i) {
    int k = getp(p[i]);
    int t;
    if (dist(l, k) < dist(r, k)) {
      if (dist(l, k) < dist(p[i], k)) l = p[i];
    } else {
      if (dist(r, k) < dist(p[i], k)) r = p[i];
    }
    printf("%d\n", dist(l, r));
  }
}
