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 N = 2016;
bitset<N> v[N];
bitset<N> ones[N + 1];
set<pair<int, int> > bad;
void rem(int i, int j) {
  if (i > j) swap(i, j);
  bad.erase(pair<int, int>(i, j));
}
void check(int i, int j) {
  if (v[i] != (v[i] & v[j])) {
    if (i > j) swap(i, j);
    bad.insert(pair<int, int>(i, j));
  }
}
const int BB = 1 << 16;
int small[BB];
int smallest_bit(unsigned int v) {
  if (!v) return 1e9;
  unsigned int v1 = v & (BB - 1);
  if (v1)
    return small[v1];
  else
    return 16 + small[(v ^ v1) >> 16];
}
int get_first(const bitset<N>& a) {
  int ans = N;
  const int B = 32;
  const unsigned int* c = reinterpret_cast<const unsigned int*>(&a);
  for (int i = N / B - 1; i >= 0; --i) {
    ans = min(ans, i * B + smallest_bit(c[i]));
  }
  return ans;
}
const int DEBUG = 0;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  for (int i = 2; i < BB; i += 2) small[i] = 1 + small[i / 2];
  int n = 4, m = 4, T = 2500000;
  if (!DEBUG) cin >> n >> m >> T;
  vector<vector<int> > deb(n, vector<int>(m));
  for (int i = 0; i < N; ++i) {
    ones[i + 1] = ones[i];
    ones[i + 1].set(i);
  }
  set<pair<int, int> > w;
  vector<int> sz(n);
  for (int i = 0; i < n; ++i) w.insert(pair<int, int>(sz[i], i));
  bitset<N> tmp;
  for (int q = 0; q < T; ++q) {
    int a = rand() % n + 1, l = rand() % m + 1, r = rand() % m + 1;
    if (l > r) swap(l, r);
    if (!DEBUG) cin >> a >> l >> r;
    --a;
    if (DEBUG)
      for (int i = l - 1; i <= r - 1; ++i) deb[a][i] ^= 1;
    auto it = w.find(pair<int, int>(sz[a], a));
    int pr = -1, nx = -1;
    if (it != w.begin()) {
      auto it1 = it;
      --it1;
      pr = it1->second;
      rem(it1->second, a);
    }
    auto it1 = it;
    ++it1;
    if (it1 != w.end()) {
      nx = it1->second;
      rem(a, it1->second);
    }
    if (pr != -1 && nx != -1) check(pr, nx);
    w.erase(pair<int, int>(sz[a], a));
    v[a] ^= ones[r] ^ ones[l - 1];
    sz[a] = v[a].count();
    it = w.insert(pair<int, int>(sz[a], a)).first;
    pr = -1, nx = -1;
    if (it != w.begin()) {
      auto it1 = it;
      --it1;
      pr = it1->second;
      check(pr, a);
    }
    it1 = it;
    ++it1;
    if (it1 != w.end()) {
      nx = it1->second;
      check(a, nx);
    }
    if (pr != -1 && nx != -1) rem(pr, nx);
    if (bad.empty()) {
      cout << "-1\n";
      if (DEBUG) {
        for (int i = 0; i < n; ++i) {
          for (int j = 0; j < m; ++j) cerr << deb[i][j];
          cerr << endl;
        }
        for (int i = 0; i < n; ++i)
          for (int j = 0; j < m; ++j)
            for (int i1 = i + 1; i1 < n; ++i1)
              for (int j1 = j + 1; j1 < m; ++j1) {
                assert(!(deb[i][j] == deb[i1][j1] && deb[i][j1] == deb[i1][j] &&
                         deb[i][j] != deb[i][j1]));
              }
      }
    } else {
      int i = bad.begin()->first, j = bad.begin()->second;
      tmp = v[i] & v[j];
      int c1 = get_first(v[i] ^ tmp), c2 = get_first(v[j] ^ tmp);
      if (c1 > c2) swap(c1, c2);
      cout << i + 1 << ' ' << c1 + 1 << ' ' << j + 1 << ' ' << c2 + 1 << '\n';
      assert(c1 < m && c2 < m);
      if (DEBUG) {
        for (int i = 0; i < n; ++i) {
          for (int j = 0; j < m; ++j) assert(v[i][j] == deb[i][j]);
        }
        assert(deb[i][c1] == deb[j][c2] && deb[i][c2] == deb[j][c1] &&
               deb[i][c1] != deb[i][c2]);
      }
    }
  }
  return 0;
}