Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = v * 10 + c - '0';
    c = getchar();
  }
  return v * f;
}
const int Maxn = 2005;
int Lb[65536];
int pc[65536];
int lb(unsigned long long t) {
  if (t & 65535) return Lb[t & 65535];
  if (t >> 16 & 65535) return Lb[t >> 16 & 65535] + 16;
  if (t >> 32 & 65535) return Lb[t >> 32 & 65535] + 32;
  return Lb[t >> 48] + 48;
}
int popCount(unsigned long long t) {
  return pc[t & 0xFFFF] + pc[t >> 16 & 0xFFFF] + pc[t >> 32 & 0xFFFF] +
         pc[t >> 48 & 0xFFFF];
}
struct Bset {
  unsigned long long data[40];
  Bset() { memset(data, 0, sizeof(data)); }
  Bset operator^(Bset B) {
    Bset ret;
    for (int i = 0; i < 40; i++) {
      ret.data[i] = data[i] ^ B.data[i];
    }
    return ret;
  }
  Bset operator&(Bset B) {
    Bset ret;
    for (int i = 0; i < 40; i++) {
      ret.data[i] = data[i] & B.data[i];
    }
    return ret;
  }
  bool operator==(const Bset &B) const {
    for (int i = 0; i < 40; i++) {
      if (data[i] != B.data[i]) return false;
    }
    return true;
  }
  int lowbit() {
    for (int i = 0; i < 40; i++) {
      if (data[i]) {
        return lb(data[i]) + (i << 6);
      }
    }
    assert(false);
  }
  void set(int pos) { data[pos >> 6] |= 1ull << (pos & 63); }
  int count() {
    int ret = 0;
    for (int i = 0; i < 40; i++) {
      ret += popCount(data[i]);
    }
    return ret;
  }
} B[Maxn];
Bset Bs[Maxn];
int n, m, q;
void _init() {
  for (int i = 1; i < 65536; i++) {
    Lb[i] = log2(i & -i);
    pc[i] = pc[i - (i & -i)] + 1;
  }
  for (int i = 0; i < Maxn; i++) {
    if (i != 0) Bs[i] = Bs[i - 1];
    Bs[i].set(i);
  }
}
set<pair<int, int> > S;
set<pair<int, int> > Og;
int lstc[Maxn];
void Del(int id) {
  set<pair<int, int> >::iterator it = S.find(make_pair(lstc[id], id)), it2;
  int f = 0;
  if (it != S.begin()) {
    it2 = it;
    it2--;
    if (Og.find(make_pair(it2->second, it->second)) != Og.end()) {
      Og.erase(make_pair(it2->second, it->second));
    }
    f++;
  }
  it2 = it;
  it2++;
  if (it2 != S.end()) {
    if (Og.find(make_pair(it->second, it2->second)) != Og.end()) {
      Og.erase(make_pair(it->second, it2->second));
    }
    f++;
  }
  if (f == 2) {
    it--;
    int id1 = it->second, id2 = it2->second;
    if (!((B[id1] & B[id2]) == B[id1])) {
      Og.insert(make_pair(id1, id2));
    }
  }
  S.erase(make_pair(lstc[id], id));
}
void Ins(int id) {
  int c = B[id].count();
  lstc[id] = c;
  S.insert(make_pair(c, id));
  assert(S.size() == n);
  set<pair<int, int> >::iterator it = S.find(make_pair(c, id)), it2;
  if (it != S.begin()) {
    it2 = it;
    it2++;
    it--;
    if (it2 != S.end()) {
      if (Og.find(make_pair(it->second, it2->second)) != Og.end()) {
        Og.erase(make_pair(it->second, it2->second));
      }
      int id2 = it2->second;
      if (!((B[id] & B[id2]) == B[id])) {
        Og.insert(make_pair(id, id2));
      }
    }
    int id2 = it->second;
    if (!((B[id] & B[id2]) == B[id2])) {
      Og.insert(make_pair(id2, id));
    }
    return;
  }
  it++;
  if (it != S.end()) {
    int id2 = it->second;
    if (!((B[id] & B[id2]) == B[id])) {
      Og.insert(make_pair(id, id2));
    }
  }
}
int main() {
  _init();
  n = read();
  m = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    S.insert(make_pair(0, i));
  }
  while (q--) {
    int a, l, r;
    a = read();
    l = read();
    r = read();
    Del(a);
    B[a] = B[a] ^ Bs[l - 1];
    B[a] = B[a] ^ Bs[r];
    Ins(a);
    if (Og.empty()) {
      printf("-1\n");
      continue;
    }
    pair<int, int> t = *Og.begin();
    int x = t.first, y = t.second;
    if (x > y) swap(x, y);
    Bset tmp = B[x] & B[y], tmpx = tmp ^ B[x], tmpy = tmp ^ B[y];
    int xx = tmpx.lowbit(), yy = tmpy.lowbit();
    if (xx > yy) swap(xx, yy);
    printf("%d %d %d %d\n", x, xx, y, yy);
  }
  return 0;
}