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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int N = 2010;
std::bitset<N> row[N];
std::bitset<N> ones[N];
map<pair<int, int>, bool> A;
set<pair<int, int> > can;
bool contain(int u, int v) { return (row[u] & row[v]) == row[v]; }
void erase_row(int cnt, int x) {
  auto it = A.find({cnt, x});
  if (it->second) {
    auto nit = next(it);
    can.erase({it->first.second, nit->first.second});
  }
  if (it != A.begin()) {
    auto pit = prev(it);
    if (pit->second) can.erase({pit->first.second, it->first.second});
    auto nit = next(it);
    if (nit == A.end()) {
      pit->second = false;
    } else {
      pit->second = !contain(nit->first.second, pit->first.second);
      if (pit->second) can.insert({pit->first.second, nit->first.second});
    }
  }
  A.erase(it);
}
void insert_row(int cnt, int x) {
  A[{cnt, x}] = false;
  auto it = A.find({cnt, x});
  auto nit = next(it);
  if (nit == A.end()) {
    it->second = false;
  } else {
    it->second = !contain(nit->first.second, it->first.second);
    if (it->second) can.insert({it->first.second, nit->first.second});
  }
  if (it != A.begin()) {
    auto pit = prev(it);
    if (pit->second) can.erase({pit->first.second, nit->first.second});
    pit->second = !contain(it->first.second, pit->first.second);
    if (pit->second) can.insert({pit->first.second, it->first.second});
  }
}
void print(int x1, int x2) {
  const auto& t1 = row[x1] & ~row[x2];
  int y1, y2;
  for (y1 = 0; !t1[y1]; ++y1)
    ;
  const auto& t2 = ~row[x1] & row[x2];
  for (y2 = 0; !t2[y2]; ++y2)
    ;
  if (x1 > x2) swap(x1, x2);
  if (y1 > y2) swap(y1, y2);
  printf("%d %d %d %d\n", x1 + 1, y1 + 1, x2 + 1, y2 + 1);
}
int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j < i; ++j) ones[i][j] = true;
  }
  for (int i = 0; i < n; ++i) A[{0, i}] = false;
  while (q--) {
    int x, y1, y2;
    scanf("%d%d%d", &x, &y1, &y2);
    --x;
    --y1;
    int old_cnt = row[x].count();
    row[x] ^= ones[y2] ^ ones[y1];
    int new_cnt = row[x].count();
    erase_row(old_cnt, x);
    insert_row(new_cnt, x);
    if (can.empty()) {
      puts("-1");
    } else {
      print(can.begin()->first, can.begin()->second);
    }
  }
  return 0;
}