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 T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  x = (x > y ? y : x);
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  x = (x < y ? y : x);
}
using ll = long long;
using ull = unsigned long long;
const string FILENAME = "input";
const int MAXN = 2022;
const unsigned long long kekT = 18446744073709551615ULL;
struct mybitset {
  vector<unsigned long long> st;
  void init(int n) { st.resize(((n + 63) >> 6), 0); }
  void flip(int l, int r) {
    l--, r--;
    for (int i = (l >> 6); i <= (r >> 6); i++) {
      if (i != (l >> 6) && i != (r >> 6)) {
        st[i] ^= kekT;
      } else {
        if (i == (l >> 6) && i == (r >> 6)) {
          for (int j = (l & 63); j <= (r & 63); j++) {
            st[i] ^= (1ULL << j);
          }
        } else {
          if (i == (l >> 6)) {
            for (int j = (l & 63); j < 64; j++) {
              st[i] ^= (1ULL << j);
            }
          } else if (i == (r >> 6)) {
            for (int j = 0; j <= (r & 63); j++) {
              st[i] ^= (1ULL << j);
            }
          }
        }
      }
    }
  }
  int count() {
    int res = 0;
    for (int i = 0; i < (int)(st).size(); i++) {
      res += __builtin_popcountll(st[i]);
    }
    return res;
  }
};
mybitset operator^(const mybitset &a, const mybitset &b) {
  mybitset c;
  c.init((int)(a.st).size() * 64);
  for (int i = 0; i < (int)(a.st).size(); i++) {
    c.st[i] = a.st[i] ^ b.st[i];
  }
  return c;
}
mybitset operator&(const mybitset &a, const mybitset &b) {
  mybitset c;
  c.init((int)(a.st).size() * 64);
  for (int i = 0; i < (int)(a.st).size(); i++) {
    c.st[i] = a.st[i] & b.st[i];
  }
  return c;
}
bool operator==(const mybitset &a, const mybitset &b) {
  for (int i = 0; i < (int)(a.st).size(); i++) {
    if (a.st[i] != b.st[i]) {
      return false;
    }
  }
  return true;
}
int n, m, q;
set<pair<int, int> > st;
mybitset b[MAXN];
int cur[MAXN];
set<pair<int, int> > kek;
void check(int i, int j, int mod) {
  if (!((b[i] & b[j]) == b[i])) {
    if (!((b[i] & b[j]) == b[j])) {
      if (mod == 1) {
        kek.insert({min(i, j), max(i, j)});
      } else {
        kek.erase({min(i, j), max(i, j)});
      }
    }
  }
}
void checks(int id, int mod) {
  auto it = st.lower_bound(make_pair(cur[id], id));
  int frt = -1, ft1 = -1;
  if (it != st.end()) {
    it++;
    if (it != st.end()) {
      frt = it->second;
      check(id, it->second, mod);
    }
    it--;
  }
  if (it != st.begin()) {
    it--;
    ft1 = it->second;
    check(it->second, id, mod);
  }
  if (frt > -1 && ft1 > -1) {
    check(frt, ft1, mod * -1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> q;
  for (int i = 0; i < n; i++) {
    b[i].init(m);
    st.insert({0, i});
  }
  for (int it = 0; it < q; it++) {
    int a, l, r;
    cin >> a >> l >> r;
    a--;
    checks(a, -1);
    st.erase({cur[a], a});
    b[a].flip(l, r);
    cur[a] = b[a].count();
    st.insert({cur[a], a});
    checks(a, 1);
    if (kek.empty()) {
      cout << -1 << '\n';
      continue;
    }
    auto p = *kek.begin();
    int i = p.first;
    int j = p.second;
    assert(i != j);
    assert(!((b[i] & b[j]) == b[i]));
    assert(!((b[i] & b[j]) == b[j]));
    int pt = -1;
    int pt1 = -1;
    for (int t = 0; t < (int)(b[i].st).size(); t++) {
      auto x = b[i].st[t] ^ b[j].st[t];
      if (x & (b[i].st[t])) {
        ull xx = x & (b[i].st[t]);
        if (pt == -1) {
          for (int k = 0; k < 64; k++) {
            if (xx & (1ULL << k)) {
              pt = (t << 6) + k;
              break;
            }
          }
        }
      }
      if (x & (b[j].st[t])) {
        ull xx = x & (b[j].st[t]);
        if (pt1 == -1) {
          for (int k = 0; k < 64; k++) {
            if (xx & (1ULL << k)) {
              pt1 = (t << 6) + k;
              break;
            }
          }
        }
      }
    }
    if (i > j) {
      swap(i, j);
    }
    if (pt > pt1) {
      swap(pt, pt1);
    }
    cout << i + 1 << ' ' << pt + 1 << ' ' << j + 1 << ' ' << pt1 + 1 << '\n';
  }
  return 0;
}