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;
short get_first_dif(vector<uint64_t>& smaller, vector<uint64_t>& larger) {
  for (int i = 0; i < (int)smaller.size(); i++)
    if ((smaller[i] & larger[i]) != smaller[i]) return i + 1;
  return 0;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int N, M, Q, B = 64;
  cin >> N >> M >> Q;
  vector<vector<uint64_t> > X(N, vector<uint64_t>(M / B + 1, 0));
  vector<vector<short> > popcount(N, vector<short>(M / B + 1, 0));
  vector<pair<short, short> > pop_order(N);
  vector<short> first_dif(N - 1, 0);
  for (int i = 0; i < N; i++) pop_order[i] = {0, i};
  for (int q = 0; q < Q; q++) {
    int a, l, r;
    cin >> a >> l >> r;
    a--, l--;
    for (uint64_t x = X[a][l / B] >> (l % B); l % B != 0 && l < r;
         x >>= 1, l++) {
      if (x & 1)
        popcount[a][l / B] -= 1;
      else
        popcount[a][l / B] += 1;
      X[a][l / B] ^= 1ULL << (l % B);
    }
    if (l != r)
      for (uint64_t x = X[a][(r - 1) / B]; r % B != 0 && l < r; r--) {
        if ((x >> ((r - 1) % B)) & 1)
          popcount[a][(r - 1) / B] -= 1;
        else
          popcount[a][(r - 1) / B] += 1;
        X[a][(r - 1) / B] ^= 1ULL << ((r - 1) % B);
      }
    for (int i = l / B; i < r / B; i++) {
      X[a][i] = ~X[a][i];
      popcount[a][i] = B - popcount[a][i];
    }
    short pop_new = 0;
    for (int i = 0; i <= M / B; i++) pop_new += popcount[a][i];
    int id = 0;
    while (pop_order[id].second != a) id++;
    if (pop_new > pop_order[id].first) {
      int id_new = id + 1;
      while (id_new < N && pop_order[id_new].first < pop_new) id_new++;
      for (int i = id + 1; i < id_new; i++) pop_order[i - 1] = pop_order[i];
      for (int i = id + 1; i < id_new - 1; i++) first_dif[i - 1] = first_dif[i];
      pop_order[id_new - 1] = {pop_new, a};
      if (id_new < N)
        first_dif[id_new - 1] =
            get_first_dif(X[a], X[pop_order[id_new].second]);
      if (id_new >= 2)
        first_dif[id_new - 2] =
            get_first_dif(X[pop_order[id_new - 2].second], X[a]);
      if (id && id_new != id + 1)
        first_dif[id - 1] =
            get_first_dif(X[pop_order[id - 1].second], X[pop_order[id].second]);
    } else if (pop_new < pop_order[id].first) {
      int id_new = id - 1;
      while (id_new >= 0 && pop_order[id_new].first > pop_new) id_new--;
      for (int i = id - 1; i > id_new; i--) pop_order[i + 1] = pop_order[i];
      for (int i = id - 2; i > id_new; i--) first_dif[i + 1] = first_dif[i];
      pop_order[id_new + 1] = {pop_new, a};
      if (id_new >= 0)
        first_dif[id_new] = get_first_dif(X[pop_order[id_new].second], X[a]);
      if (id_new < N - 2)
        first_dif[id_new + 1] =
            get_first_dif(X[a], X[pop_order[id_new + 2].second]);
      if (id < N - 1 && id_new != id - 1)
        first_dif[id] =
            get_first_dif(X[pop_order[id].second], X[pop_order[id + 1].second]);
    } else {
      pop_order[id].first = pop_new;
      if (id < N - 1)
        first_dif[id] = get_first_dif(X[a], X[pop_order[id + 1].second]);
      if (id)
        first_dif[id - 1] = get_first_dif(X[pop_order[id - 1].second], X[a]);
    }
    bool found = false;
    for (int i = 0; i < N - 1; i++)
      if (first_dif[i]) {
        int r1 = pop_order[i].second, r2 = pop_order[i + 1].second;
        for (int j = 0; j <= M / B; j++)
          if ((X[r1][j] & X[r2][j]) != X[r2][j]) {
            int c1 = first_dif[i] - 1, c2 = j, d1 = 0, d2 = 0;
            while (((X[r1][c1] >> d1) & 1) * 2 + ((X[r2][c1] >> d1) & 1) != 2)
              d1++;
            while (((X[r1][c2] >> d2) & 1) * 2 + ((X[r2][c2] >> d2) & 1) != 1)
              d2++;
            c1 = c1 * B + d1, c2 = c2 * B + d2;
            if (r1 > r2) swap(r1, r2);
            if (c1 > c2) swap(c1, c2);
            cout << r1 + 1 << " " << c1 + 1 << " " << r2 + 1 << " " << c2 + 1
                 << "\n";
            break;
          }
        found = true;
        break;
      }
    if (!found) cout << "-1\n";
  }
}