Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of itself and access to it when it is modified.

After reaching home Alina decided to invent her own persistent data structure. Inventing didn't take long: there is a bookcase right behind her bed. Alina thinks that the bookcase is a good choice for a persistent data structure. Initially the bookcase is empty, thus there is no book at any position at any shelf.

The bookcase consists of n shelves, and each shelf has exactly m positions for books at it. Alina enumerates shelves by integers from 1 to n and positions at shelves — from 1 to m. Initially the bookcase is empty, thus there is no book at any position at any shelf in it.

Alina wrote down q operations, which will be consecutively applied to the bookcase. Each of the operations has one of four types:

  * 1 i j — Place a book at position j at shelf i if there is no book at it.
  * 2 i j — Remove the book from position j at shelf i if there is a book at it.
  * 3 i — Invert book placing at shelf i. This means that from every position at shelf i which has a book at it, the book should be removed, and at every position at shelf i which has not book at it, a book should be placed.
  * 4 k — Return the books in the bookcase in a state they were after applying k-th operation. In particular, k = 0 means that the bookcase should be in initial state, thus every book in the bookcase should be removed from its position.



After applying each of operation Alina is interested in the number of books in the bookcase. Alina got 'A' in the school and had no problem finding this values. Will you do so?

Input

The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 103, 1 ≤ q ≤ 105) — the bookcase dimensions and the number of operations respectively.

The next q lines describes operations in chronological order — i-th of them describes i-th operation in one of the four formats described in the statement.

It is guaranteed that shelf indices and position indices are correct, and in each of fourth-type operation the number k corresponds to some operation before it or equals to 0.

Output

For each operation, print the number of books in the bookcase after applying it in a separate line. The answers should be printed in chronological order.

Examples

Input

2 3 3
1 1 1
3 2
4 0


Output

1
4
0


Input

4 2 6
3 2
2 2 2
3 3
3 2
2 2 2
3 2


Output

2
1
3
3
2
4


Input

2 2 2
3 2
2 2 1


Output

2
1

Note

<image>

This image illustrates the second sample case.
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 0x0FFFFFFF;
const int nil = -1;
const int root = nil + 1;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inline bool read(long long& val) { return scanf("%I64d", &val) != -1; }
inline bool read(double& val) { return scanf("%lf", &val) != -1; }
inline bool read(char* val) { return scanf("%s", val) != -1; }
template <class T1, class T2>
inline bool read(T1& a, T2& b) {
  return read(a) && read(b);
}
template <class T1, class T2, class T3>
inline bool read(T1& a, T2& b, T3& c) {
  return read(a) && read(b) && read(c);
}
template <class T1, class T2, class T3, class T4>
inline bool read(T1& a, T2& b, T3& c, T4& d) {
  return read(a) && read(b) && read(c) && read(d);
}
template <class T1, class T2, class T3, class T4, class T5>
inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) {
  return read(a) && read(b) && read(c) && read(d) && read(e);
}
template <class T>
T gcd(T a, T b) {
  for (T r; b != 0; r = a % b, a = b, b = r)
    ;
  return a;
}
template <class T>
T gcd(T a, T b, T& x, T& y) {
  T xa = 1, xb = 0;
  T ya = 0, yb = 1;
  while (b != 0) {
    x = xa - a / b * xb;
    xa = xb;
    xb = x;
    y = ya - a / b * yb;
    ya = yb;
    yb = y;
    T r = a % b;
    a = b;
    b = r;
  }
  x = xa;
  y = ya;
  return a;
}
void add(long long& a, long long b, long long mod) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}
void mul(long long& a, long long b, long long mod) { a = a * b % mod; }
long long pow(long long a, long long b, long long mod) {
  long long x = 1;
  for (; b != 0; b >>= 1, mul(a, a, mod))
    if (b & 1) mul(x, a, mod);
  return x;
}
long long rev(long long a, long long mod) {
  long long x, y;
  gcd(a, mod, x, y);
  while (x < 0) x += mod;
  while (x >= mod) x -= mod;
  return x;
}
long long china(long long r[], long long mod[], int n) {
  long long x = 0, m = 1;
  for (int i = 0, _ = (n); i < _; ++i) m *= mod[i];
  for (int i = 0, _ = (n); i < _; ++i) {
    long long mi = m / mod[i];
    x += r[i] * rev(mi, mod[i]) * mi;
  }
  return x % m;
}
int cmp(double a, double b) {
  if (fabs(a - b) < eps) return 0;
  return a < b ? -1 : 1;
}
template <class T, class U>
int lower_bound(T f, int l, int r, U val) {
  while (l < r) {
    int m = (l + r) / 2;
    if (f(m) < val)
      l = m + 1;
    else
      r = m;
  }
  return l;
}
template <class T, int n, int m>
void calC(T (&C)[n][m]) {
  for (int i = 0, _ = (n); i < _; ++i)
    for (int j = 0, _ = (m); j < _; ++j) C[i][j] = 0;
  for (int i = 0, _ = (n); i < _; ++i) C[i][0] = 1;
  for (int i = (1), _ = (n); i < _; ++i)
    for (int j = (1), _ = (min(i + 1, m)); j < _; ++j)
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
struct atype {
  bool set0;
  bool set1;
  bool rev;
  atype() : set0(false), set1(false), rev(false) {}
  void operator+=(atype a) {
    if (a.set0) rev = false, set1 = false, set0 = true;
    if (a.set1) rev = false, set0 = false, set1 = true;
    if (a.rev) rev = !rev;
  }
};
struct stype {
  int len, sum;
  stype(int len = 0, int sum = 0) : len(len), sum(sum) {}
  void operator+=(atype a) {
    if (a.set0) sum = 0;
    if (a.set1) sum = len;
    if (a.rev) sum = len - sum;
  }
  friend stype operator+(stype a, stype b) {
    return stype(a.len + b.len, a.sum + b.sum);
  }
};
const int N = 111111;
struct segment_tree {
  struct node {
    int l, r, Ls, Rs;
    atype a;
    stype s;
    node(int l = 0, int r = 0)
        : l(l), r(r), Ls(nil), Rs(nil), a(), s(r - l + 1) {}
    void add(atype val) {
      a += val;
      s += val;
    }
  } X[2 * N * 40];
  int id, newid;
  void atom() { newid = id; }
  int copy(int i) {
    if (i >= newid) return i;
    int j = id++;
    X[j] = X[i];
    return j;
  }
  int next(int l, int r) {
    X[id++] = node(l, r);
    return id - 1;
  }
  void down(node& x) {
    int m = (x.l + x.r) >> 1;
    X[x.Ls = x.Ls == nil ? next(x.l, m) : copy(x.Ls)].add(x.a);
    X[x.Rs = x.Rs == nil ? next(m + 1, x.r) : copy(x.Rs)].add(x.a);
    x.a = atype();
  }
  void add(node& x, int l, int r, atype a) {
    if (l <= x.l && x.r <= r) {
      x.add(a);
    } else {
      down(x);
      if (l <= X[x.Ls].r) add(X[x.Ls], l, r, a);
      if (r >= X[x.Rs].l) add(X[x.Rs], l, r, a);
      x.s = X[x.Ls].s + X[x.Rs].s;
    }
  }
  void sum(const node& x, int l, int r, stype& s) {
    if (l <= x.l && x.r <= r)
      s = x.s;
    else {
      if (x.Ls == nil) {
        s = stype(min(r, x.r) - max(l, x.l));
      } else if (l <= X[x.Ls].r && r >= X[x.Rs].l) {
        stype a, b;
        sum(X[x.Ls], l, r, a);
        sum(X[x.Rs], l, r, b);
        s = a + b;
      } else {
        sum(X[l <= X[x.Ls].r ? x.Ls : x.Rs], l, r, s);
      }
      s += x.a;
    }
  }
  int init_one(int i, int l, int r) {
    id = i;
    next(l, r);
    newid = 0;
    return i;
  }
  int init_all(int i, int l, int r) {
    init_one(i, l, r);
    if (l < r) {
      int m = (l + r) >> 1;
      init_all(id, l, m);
      init_all(id, m + 1, r);
    }
    return i;
  }
  int add(int i, int l, int r, atype a) {
    atom();
    add(X[i = copy(i)], l, r, a);
    return i;
  }
  int sum(int i, int l, int r, stype& s) {
    sum(X[i], l, r, s);
    return i;
  }
} st;
atype adds[4];
int roots[N];
int main() {
  int n, m, q;
  read(n, m, q);
  roots[0] = st.init_one(0, 0, n * m);
  adds[1].set1 = true;
  adds[2].set0 = true;
  adds[3].rev = true;
  for (int i = 0, _ = (q); i < _; ++i) {
    int t;
    read(t);
    if (t == 1 || t == 2) {
      int a, b;
      read(a, b);
      a--;
      b--;
      roots[i + 1] = st.add(roots[i], a * m + b, a * m + b, adds[t]);
    } else if (t == 3) {
      int a;
      read(a);
      a--;
      roots[i + 1] = st.add(roots[i], a * m, a * m + m - 1, adds[t]);
    } else {
      int a;
      read(a);
      roots[i + 1] = roots[a];
    }
    stype ans = 0;
    st.sum(roots[i + 1], 0, n * m, ans);
    printf("%d\n", ans.sum);
  }
  return 0;
}
