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;
bitset<2000> xx[2001];
bitset<2000> bs[2000];
int c[2000];
set<pair<int, int> > S, S2;
int main() {
  int i, j;
  int n, m, q;
  int a, l, r;
  scanf("%d %d %d", &n, &m, &q);
  for (i = 0; i < m; i++) xx[i + 1] = xx[i], xx[i + 1][i] = 1;
  for (i = 0; i < n; i++) S.insert(make_pair(c[i], i));
  for (i = 0; i < q; i++) {
    scanf("%d %d %d", &a, &l, &r);
    a--, l--, r--;
    auto it = S.find(make_pair(c[a], a));
    if (it != S.begin()) {
      auto it2 = it;
      it2--;
      if (S2.count(make_pair(it2->second, it->second)))
        S2.erase(make_pair(it2->second, it->second));
    }
    if (it != (--S.end())) {
      auto it2 = it;
      it2++;
      if (S2.count(make_pair(it->second, it2->second)))
        S2.erase(make_pair(it->second, it2->second));
    }
    if ((it != S.begin()) && (it != (--S.end()))) {
      auto it2 = it, it3 = it;
      it2--, it3++;
      if ((bs[it2->second] & bs[it3->second]) != bs[it2->second])
        S2.insert(make_pair(it2->second, it3->second));
    }
    S.erase(it);
    bs[a] ^= xx[r + 1] ^ xx[l], c[a] = bs[a].count();
    it = S.insert(make_pair(c[a], a)).first;
    if (it != S.begin()) {
      auto it2 = it;
      it2--;
      if ((bs[it2->second] & bs[it->second]) != bs[it2->second])
        S2.insert(make_pair(it2->second, it->second));
    }
    if (it != (--S.end())) {
      auto it2 = it;
      it2++;
      if ((bs[it->second] & bs[it2->second]) != bs[it->second])
        S2.insert(make_pair(it->second, it2->second));
    }
    if ((it != S.begin()) && (it != (--S.end()))) {
      auto it2 = it, it3 = it;
      it2--, it3++;
      if (S2.count(make_pair(it2->second, it3->second)))
        S2.erase(make_pair(it2->second, it3->second));
    }
    if (S2.empty())
      printf("-1\n");
    else {
      int y1 = S2.begin()->first, y2 = S2.begin()->second;
      if (y1 > y2) swap(y1, y2);
      bitset<2000> b = bs[y1] & ~bs[y2];
      for (j = 0; j < m; j++) {
        if (b[j]) break;
      }
      int x1 = j;
      b = ~bs[y1] & bs[y2];
      for (j = 0; j < m; j++) {
        if (b[j]) break;
      }
      int x2 = j;
      if (x1 > x2) swap(x1, x2);
      printf("%d %d %d %d\n", y1 + 1, x1 + 1, y2 + 1, x2 + 1);
    }
  }
  return 0;
}