Recently biologists came to a fascinating conclusion about how to find a chameleon mood. Consider chameleon body to be a rectangular table n × m, each cell of which may be green or blue and may change between these two colors. We will denote as (x, y) (1 ≤ x ≤ n, 1 ≤ y ≤ m) the cell in row x and column y.

Let us define a chameleon good mood certificate to be four cells which are corners of some subrectangle of the table, such that colors in opposite cells among these four are similar, and at the same time not all of the four cell colors are similar. Formally, it is a group of four cells (x_1, y_1), (x_1, y_2), (x_2, y_1), (x_2, y_2) for some 1 ≤ x_1 < x_2 ≤ n, 1 ≤ y_1 < y_2 ≤ m, that colors of (x_1, y_1) and (x_2, y_2) coincide and colors of (x_1, y_2) and (x_2, y_1) coincide, but not all of the four cells share the same color. It was found that whenever such four cells are present, chameleon is in good mood, and vice versa: if there are no such four cells, chameleon is in bad mood.

You are asked to help scientists write a program determining the mood of chameleon. Let us consider that initially all cells of chameleon are green. After that chameleon coloring may change several times. On one change, colors of contiguous segment of some table row are replaced with the opposite. Formally, each color change is defined by three integers a, l, r (1 ≤ a ≤ n, 1 ≤ l ≤ r ≤ m). On such change colors of all cells (a, b) such that l ≤ b ≤ r are replaced with the opposite.

Write a program that reports mood of the chameleon after each change. Additionally, if the chameleon mood is good, program should find out any four numbers x_1, y_1, x_2, y_2 such that four cells (x_1, y_1), (x_1, y_2), (x_2, y_1), (x_2, y_2) are the good mood certificate.

Input

The first line of input contains three integers n, m, q (1 ≤ n, m ≤ 2000, 1 ≤ q ≤ 500 000), the sizes of the table and the number of changes respectively. 

Each of the following q lines contains 3 integers a_i, l_i, r_i (1 ≤ a_i ≤ n, 1 ≤ l_i ≤ r_i ≤ m), describing i-th coloring change.

Output

Print q lines. In the i-th line report the chameleon mood after first i color changes for all 1 ≤ i ≤ q.

If chameleon is in bad mood, print the only integer -1.

Otherwise, print four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 < x_2 ≤ n, 1 ≤ y_1 < y_2 ≤ m) such that four cells (x_1, y_1), (x_1, y_2), (x_2, y_1), (x_2, y_2) are the good mood certificate. If there are several ways to choose such four integers, print any valid one.

Examples

Input


2 2 6
1 1 1
2 2 2
2 1 1
1 2 2
2 2 2
1 1 1


Output


-1
1 1 2 2
-1
-1
-1
1 1 2 2


Input


4 3 9
2 2 3
4 1 2
2 1 3
3 2 2
3 1 3
1 2 2
4 2 3
1 1 3
3 1 3


Output


-1
2 1 4 3
-1
2 1 3 2
3 2 4 3
1 1 2 2
1 1 2 2
-1
2 1 3 2
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2048, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const long long inf = 1e18;
mt19937 rnd(time(0));
const unsigned long long T = ((unsigned long long)1 << 64) - 1;
const int LEN = maxn / 64;
struct Bitset {
  unsigned long long a[LEN];
  void build() {
    for (int i = 0; i < LEN; ++i) a[i] = 0;
  }
  void change(int l, int r) {
    int block, bt;
    while (l <= r) {
      block = l / 64;
      bt = l % 64;
      if (l % 64 == 0 && l + 63 <= r) {
        a[block] ^= T;
        l += 64;
      } else {
        a[block] ^= (1ll << bt);
        ++l;
      }
    }
  }
  int get() {
    int one = 0;
    for (int i = 0; i < LEN; ++i) {
      one += __builtin_popcountll(a[i]);
    }
    return one;
  }
  int find_one() {
    for (int i = 0; i < LEN; ++i) {
      if (a[i]) {
        for (int bt = 0; bt < 64; ++bt) {
          if ((a[i] >> bt) & 1) return i * 64 + bt;
        }
      }
    }
    return -1;
  }
};
void print(Bitset a) {
  for (int i = 0; i < LEN; ++i) {
    for (int j = 0; j < 64; ++j) {
      cout << ((a.a[i] >> j) & 1);
    }
  }
}
bool operator<(Bitset &a, Bitset &b) { return a.get() < b.get(); }
Bitset operator&(const Bitset &a, const Bitset &b) {
  Bitset c;
  c.build();
  for (int i = 0; i < LEN; ++i) {
    c.a[i] = a.a[i] & b.a[i];
  }
  return c;
}
Bitset operator|(const Bitset &a, const Bitset &b) {
  Bitset c;
  c.build();
  for (int i = 0; i < LEN; ++i) {
    c.a[i] = a.a[i] | b.a[i];
  }
  return c;
}
Bitset operator^(const Bitset &a, const Bitset &b) {
  Bitset c;
  c.build();
  for (int i = 0; i < LEN; ++i) {
    c.a[i] = a.a[i] ^ b.a[i];
  }
  return c;
}
bool operator==(const Bitset &a, const Bitset &b) {
  for (int i = 0; i < LEN; ++i) {
    if (a.a[i] != b.a[i]) return false;
  }
  return true;
}
int n, m, q;
int siz[maxn];
Bitset a[maxn];
set<pair<int, int> > ms;
set<pair<pair<int, int>, pair<int, int> > > ans;
pair<int, int> ptr[maxn][maxn];
void get(pair<int, int> a1, pair<int, int> b1, int ty) {
  int A = a1.second;
  int B = b1.second;
  if (A > B) swap(A, B);
  Bitset aa = (a[A] ^ a[B]) & a[B];
  Bitset bb = (a[B] ^ a[A]) & a[A];
  int y1228 = aa.find_one();
  int y2 = bb.find_one();
  if (y1228 > y2) swap(y1228, y2);
  if (ptr[A][B].first != -1) {
    ans.erase(make_pair(make_pair(A, ptr[A][B].first),
                        make_pair(B, ptr[A][B].second)));
  }
  if (ty == -1) {
    ptr[A][B] = {-1, -1};
    return;
  }
  if (ty == 1) {
    if (y1228 != -1) {
      ans.insert(make_pair(make_pair(A, y1228), make_pair(B, y2)));
    }
    if (y1228 == -1) y2 = -1;
    ptr[A][B] = {y1228, y2};
  }
}
void solve() {
  for (int i = 0; i < maxn; ++i) {
    for (int j = 0; j < maxn; ++j) {
      ptr[i][j] = {-1, -1};
    }
  }
  cin >> n >> m >> q;
  for (int i = 0; i < n; ++i) {
    a[i].build();
    ms.insert({0, i});
  }
  while (q--) {
    int id, l, r;
    cin >> id >> l >> r;
    --l, --r, --id;
    auto M = ms.lower_bound(make_pair(a[id].get(), id));
    auto L = M;
    if (M != ms.begin()) {
      L = --M;
      ++M;
    }
    auto R = ++M;
    --M;
    if (M != ms.begin()) get(*L, *M, -1);
    if (M != --ms.end()) get(*M, *R, -1);
    if (M != ms.begin() && M != --ms.end()) get(*L, *R, 1);
    ms.erase(M);
    a[id].change(l, r);
    ms.insert(make_pair(a[id].get(), id));
    M = ms.lower_bound(make_pair(a[id].get(), id));
    if (M != ms.begin()) {
      L = --M;
      ++M;
    }
    R = ++M;
    --M;
    if (M != ms.begin() && M != --ms.end()) get(*L, *R, -1);
    if (M != ms.begin()) get(*L, *M, 1);
    if (M != (--ms.end())) get(*M, *R, 1);
    if (ans.empty())
      cout << "-1\n";
    else {
      pair<pair<int, int>, pair<int, int> > t = *ans.begin();
      cout << t.first.first + 1 << " " << t.first.second + 1 << " "
           << t.second.first + 1 << " " << t.second.second + 1 << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
