#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 1e6 + 10;
namespace lct {
struct node {
  int p, ch[2];
  int sz;
  node() {
    p = ch[0] = ch[1] = -1;
    sz = 1;
  }
};
node t[MAX];
void update(int x) {
  t[x].sz = 1;
  for (int i = 0; i < 2; i++)
    if (t[x].ch[i] + 1) t[x].sz += t[t[x].ch[i]].sz;
}
bool is_root(int x) {
  return t[x].p == -1 or (t[t[x].p].ch[0] != x and t[t[x].p].ch[1] != x);
}
void rotate(int x) {
  int p = t[x].p, pp = t[p].p;
  if (!is_root(p)) t[pp].ch[t[pp].ch[1] == p] = x;
  bool d = t[p].ch[0] == x;
  t[p].ch[!d] = t[x].ch[d], t[x].ch[d] = p;
  if (t[p].ch[!d] + 1) t[t[p].ch[!d]].p = p;
  t[x].p = pp, t[p].p = x;
  update(p), update(x);
}
void splay(int x) {
  while (!is_root(x)) {
    int p = t[x].p, pp = t[p].p;
    if (!is_root(p)) rotate((t[pp].ch[0] == p) ^ (t[p].ch[0] == x) ? x : p);
    rotate(x);
  }
}
int access(int v) {
  int last = -1;
  for (int w = v; w + 1; update(last = w), splay(v), w = t[v].p)
    splay(w), t[w].ch[1] = (last == -1 ? -1 : v);
  return last;
}
void link(int v, int w) {
  access(v);
  t[v].p = w;
}
int lca(int v, int w) { return access(v); }
int query(int v, int w, bool first = 1) {
  int ans = 0;
  static int val;
  if (first) {
    access(v);
    val = t[v].sz;
  }
  ans += val;
  access(w);
  ans += t[w].sz;
  int l = lca(v, w);
  access(l);
  ans -= 2 * (t[l].sz - 1) + 1;
  return ans;
}
}  // namespace lct
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 2; i <= 4; i++) lct::link(i, 1);
  int l = 2, r = 3, qt = 4, diam = 3;
  int q;
  cin >> q;
  while (q--) {
    int p;
    cin >> p;
    lct::link(++qt, p);
    lct::link(++qt, p);
    int L = lct::query(qt, l), R = lct::query(qt, r, 0);
    diam = max({diam, L, R});
    if (diam == L)
      r = qt;
    else if (diam == R)
      l = qt;
    cout << diam - 1 << '\n';
  }
  exit(0);
}
