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;
const int K = 2048;
const int LEN = K / 64;
struct My_bitset {
  unsigned long long arr[LEN];
  int cnt;
  My_bitset() {
    for (int i = 0; i < LEN; ++i) arr[i] = 0;
    cnt = 0;
  }
  int count() { return cnt; }
  bool is_subset(My_bitset& b) {
    for (int i = 0; i < LEN; ++i) {
      unsigned long long X = b.arr[i] & arr[i];
      unsigned long long T = X ^ b.arr[i];
      if (T != 0) return false;
    }
    return true;
  }
  void change(int l, int r) {
    for (int i = 0; i < LEN; ++i) {
      int L = i * 64, R = (i + 1) * 64 - 1;
      L = max(L, l), R = min(R, r);
      if (L > R) continue;
      cnt -= __builtin_popcountll(arr[i]);
      unsigned long long a = L % 64, b = R % 64;
      if (b == 63)
        b = ULLONG_MAX;
      else
        b = (1LL << (b + 1)) - 1;
      a = (1LL << a) - 1;
      arr[i] ^= (b - a);
      cnt += __builtin_popcountll(arr[i]);
    }
  }
  int special(My_bitset& b) {
    for (int i = 0; i < LEN; ++i) {
      unsigned long long X = b.arr[i] & arr[i];
      unsigned long long T = X ^ b.arr[i];
      if (T == 0) continue;
      for (int j = 0; j < 64; ++j) {
        unsigned long long ba = (1ULL << j) & T;
        if (ba == 0) continue;
        return 64 * i + j;
      }
    }
  }
};
vector<My_bitset> bitsets;
set<int> bad_bitsets;
struct cmp {
  bool operator()(const int& a, const int& b) const {
    int A = bitsets[a].count(), B = bitsets[b].count();
    if (A != B) return (A < B);
    return (a < b);
  }
};
set<int, cmp> ms;
void change_triplet(int a, int b, int c, bool is_removal) {
  if (a == -1 && c == -1) return;
  if (c == -1) {
    c = b;
    b = a;
    a = -1;
  }
  if (a == -1) {
    bool resb_c = bitsets[c].is_subset(bitsets[b]);
    if (is_removal) {
      if (!resb_c) bad_bitsets.erase(bad_bitsets.find(b));
    } else {
      if (!resb_c) bad_bitsets.insert(b);
    }
    return;
  }
  bool resa_b = bitsets[b].is_subset(bitsets[a]);
  bool resb_c = bitsets[c].is_subset(bitsets[b]);
  bool resa_c = bitsets[c].is_subset(bitsets[a]);
  if (is_removal) {
    if (!resa_b) bad_bitsets.erase(bad_bitsets.find(a));
    if (!resb_c) bad_bitsets.erase(bad_bitsets.find(b));
    if (!resa_c) bad_bitsets.insert(a);
  } else {
    if (!resa_c) bad_bitsets.erase(bad_bitsets.find(a));
    if (!resa_b) bad_bitsets.insert(a);
    if (!resb_c) bad_bitsets.insert(b);
  }
}
void print_answer(int x) {
  auto it = ms.find(x);
  it++;
  int y = *it;
  int a = bitsets[x].special(bitsets[y]), b = bitsets[y].special(bitsets[x]);
  cout << min(x, y) + 1 << " " << min(a, b) + 1 << " " << max(x, y) + 1 << " "
       << max(a, b) + 1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  bitsets.assign(n, {});
  for (int i = 0; i < n; ++i) ms.insert(i);
  for (int i = 0; i < q; ++i) {
    int a, l, r;
    cin >> a >> l >> r;
    a--, l--, r--;
    auto it = ms.find(a);
    int first_t = -1, second_t = a, third_t = -1;
    if (it != ms.begin()) {
      it--;
      first_t = (*it);
      it++;
    }
    it++;
    if (it != ms.end()) {
      third_t = (*it);
    }
    change_triplet(first_t, second_t, third_t, true);
    ms.erase(ms.find(a));
    bitsets[a].change(l, r);
    ms.insert(a);
    it = ms.find(a);
    first_t = -1, second_t = a, third_t = -1;
    if (it != ms.begin()) {
      it--;
      first_t = (*it);
      it++;
    }
    it++;
    if (it != ms.end()) {
      third_t = (*it);
    }
    change_triplet(first_t, second_t, third_t, false);
    if (bad_bitsets.size() == 0) {
      cout << "-1\n";
      continue;
    }
    int bad = *bad_bitsets.begin();
    print_answer(bad);
  }
}