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;
unsigned long long hasher[63];
struct mybitset {
  unsigned a[63];
  void set(unsigned x) { a[x >> 5u] |= 1u << (x & 31u); }
  void operator^=(const mybitset& b) {
    for (unsigned i = 0; i < 63; i++) a[i] ^= b.a[i];
  }
  unsigned ffs() const {
    for (unsigned i = 0; i < 63; i++) {
      if (a[i]) {
        return (i << 5u) | __builtin_ctz(a[i]);
      }
    }
    return 2016u;
  }
  unsigned long long hash() const {
    unsigned long long h = 0;
    for (unsigned i = 0; i < 63; i++) {
      h ^= a[i] * hasher[i];
    }
    return h;
  }
  unsigned popcnt() const {
    unsigned h = 0;
    for (unsigned i = 0; i < 63; i++) {
      h += __builtin_popcount(a[i]);
    }
    return h;
  }
  mybitset minus(const mybitset& b) const {
    mybitset t;
    for (unsigned i = 0; i < 63; i++) {
      t.a[i] = a[i] & ~b.a[i];
    }
    return t;
  }
  bool notsubset(const mybitset& b) const {
    for (unsigned i = 0; i < 63; i++) {
      if (a[i] & ~b.a[i]) {
        return true;
      }
    }
    return false;
  }
};
int n, m, q;
mybitset a[2048], z[2048];
map<unsigned long long, set<unsigned>> mp[2005];
set<int> lens, dulens, adj;
vector<int> dvareda(int i, int j) {
  mybitset t1 = a[i].minus(a[j]);
  mybitset t2 = a[j].minus(a[i]);
  int u = t1.ffs();
  int v = t2.ffs();
  return {i, u, j, v};
}
vector<int> ima() {
  if (dulens.size()) {
    int x = *dulens.begin();
    int i = *mp[x].begin()->second.begin();
    int j = *next(mp[x].begin())->second.begin();
    return dvareda(i, j);
  }
  if (adj.size()) {
    int x = *adj.begin();
    int y = *lens.upper_bound(x);
    int i = *mp[x].begin()->second.begin();
    int j = *mp[y].begin()->second.begin();
    return dvareda(i, j);
  }
  return {-1};
}
void lens_erase(int c) {
  auto it = lens.find(c);
  if (it == lens.end()) return;
  adj.erase(c);
  if (it != lens.begin()) {
    adj.erase(*prev(it));
    if (next(it) != lens.end()) {
      int i = *mp[*prev(it)].begin()->second.begin();
      int j = *mp[*next(it)].begin()->second.begin();
      if (a[i].notsubset(a[j])) {
        adj.insert(*prev(it));
      }
    }
  }
  lens.erase(it);
}
void lens_insert(int c) {
  auto [it, has] = lens.insert(c);
  if (!has) return;
  if (it != lens.begin() && next(it) != lens.end()) {
    int i = *mp[*prev(it)].begin()->second.begin();
    int j = *mp[*next(it)].begin()->second.begin();
    if (a[i].notsubset(a[j])) {
      adj.erase(*prev(it));
    }
  }
  if (next(it) != lens.end()) {
    int i = *mp[*(it)].begin()->second.begin();
    int j = *mp[*next(it)].begin()->second.begin();
    if (a[i].notsubset(a[j])) {
      adj.insert(*(it));
    }
  }
  if (it != lens.begin()) {
    int i = *mp[*prev(it)].begin()->second.begin();
    int j = *mp[*(it)].begin()->second.begin();
    if (a[i].notsubset(a[j])) {
      adj.insert(*prev(it));
    }
  }
}
void dodaj(int i) {
  unsigned long long h = a[i].hash();
  unsigned c = a[i].popcnt();
  int ol = mp[c].size();
  mp[c][h].insert(i);
  int nu = mp[c].size();
  if (ol == 0 && nu == 1) {
    lens_insert(c);
  } else if (ol == 1 && nu == 2) {
    lens_erase(c);
    dulens.insert(c);
  }
}
void skloni(int i) {
  unsigned long long h = a[i].hash();
  unsigned c = a[i].popcnt();
  int ol = mp[c].size();
  mp[c][h].erase(i);
  if (mp[c][h].empty()) mp[c].erase(h);
  int nu = mp[c].size();
  if (ol == 2 && nu == 1) {
    dulens.erase(c);
    lens_insert(c);
  } else if (ol == 1 && nu == 0) {
    lens_erase(c);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  {
    mt19937 eng(
        chrono::high_resolution_clock::now().time_since_epoch().count() +
        reinterpret_cast<unsigned long>(new int) + *(new unsigned long));
    for (unsigned i = 0; i < 63; i++) {
      hasher[i] =
          uniform_int_distribution<unsigned long long>(0, -1ull)(eng) << 1 | 1;
    }
  }
  cin >> n >> m >> q;
  for (int i = 1; i <= m; i++) {
    z[i] = z[i - 1];
    z[i].set(i);
  }
  for (int i = 1; i <= n; i++) {
    mp[0][a[0].hash()].insert(i);
    lens.insert(0);
  }
  for (int _q = 0; _q < q; _q++) {
    int i, l, r;
    cin >> i >> l >> r;
    skloni(i);
    a[i] ^= z[r];
    a[i] ^= z[l - 1];
    dodaj(i);
    auto v = ima();
    if (v.size() == 4) {
      if (v[0] > v[2]) swap(v[0], v[2]);
      if (v[1] > v[3]) swap(v[1], v[3]);
    }
    for (int x : v) {
      cout << x << ' ';
    }
    cout << '\n';
  }
}