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;
int bit(unsigned long long mask, int k) { return (mask >> k) & 1; }
bool is_submask(unsigned long long mask1, unsigned long long mask2) {
  return (mask1 | mask2) == mask2;
}
int first_bit(unsigned long long mask) {
  int i;
  for (i = 0; !(mask & 1); ++i) mask >>= 1;
  return i;
}
const int B = 64;
template <int N>
struct Bitset {
  int n;
  unsigned long long val[(N + B - 1) / B];
  Bitset() {
    n = (N + B - 1) / B;
    for (int i = 0; i < n; ++i) val[i] = 0;
  }
  void operator=(Bitset<N> s) {
    n = s.n;
    for (int i = 0; i < n; ++i) val[i] = s.val[i];
  }
  Bitset operator&(Bitset<N> s) {
    Bitset<N> res;
    for (int i = 0; i < n; ++i) res.val[i] = val[i] & s.val[i];
    return res;
  }
  void operator&=(Bitset<N> s) {
    for (int i = 0; i < n; ++i) val[i] &= s.val[i];
  }
  Bitset operator|(Bitset<N> s) {
    Bitset<N> res;
    for (int i = 0; i < n; ++i) res.val[i] = val[i] | s.val[i];
    return res;
  }
  void operator|=(Bitset<N> s) {
    for (int i = 0; i < n; ++i) val[i] |= s.val[i];
  }
  Bitset operator^(Bitset<N> s) {
    Bitset<N> res;
    for (int i = 0; i < n; ++i) res.val[i] = val[i] ^ s.val[i];
    return res;
  }
  void operator^=(Bitset<N> s) {
    for (int i = 0; i < n; ++i) val[i] ^= s.val[i];
  }
  int at(int i) { return bit(val[i / B], i & (B - 1)); }
  int count() {
    int res = 0;
    for (int i = 0; i < n; ++i) res += __builtin_popcountll(val[i]);
    return res;
  }
  void set(int i, int x) {
    int pos = i / B;
    i &= B - 1;
    if (bit(val[pos], i) != x) val[pos] ^= 1LL << i;
  }
  bool is_subset(Bitset<N> s) {
    for (int i = 0; i < n; ++i)
      if (!is_submask(val[i], s.val[i])) return false;
    return true;
  }
  int first() {
    for (int i = 0; i < n; ++i)
      if (val[i]) return i * B + first_bit(val[i]);
    return -1;
  }
  void show(int m) {
    for (int i = 0; i < m; ++i) printf("%d", this->at(i));
    printf("\n");
  }
};
struct Set {
  int id, cnt;
  bool issub;
  Set(int _id, int _cnt, bool _issub) : id(_id), cnt(_cnt), issub(_issub){};
  Set() : id(-1), cnt(0), issub(false){};
  bool operator<(const Set& S) const {
    if (cnt != S.cnt) return cnt < S.cnt;
    return id < S.id;
  }
};
vector<Set> S;
struct SetCompare {
  bool operator()(const int& i, const int& j) const { return S[i] < S[j]; }
};
int main() {
  int n, m, q;
  scanf("%d %d %d", &n, &m, &q);
  if (n == 1 || m == 1) {
    while (q--) printf("-1\n");
    return 0;
  }
  const int M = 2020;
  vector<Bitset<M> > bs(n + 1), pref(m + 1);
  for (int i = 0; i < m; ++i) {
    pref[i + 1] = pref[i];
    pref[i + 1].set(i, 1);
  }
  S.resize(n + 1);
  set<int, SetCompare> sets;
  for (int i = 0; i < n; ++i) {
    S[i] = Set(i, 0, true);
    sets.insert(i);
  }
  bs[n] = pref[m];
  S[n] = Set(n, m, false);
  sets.insert(n);
  set<int> good;
  function<int(int)> prev = [&](int i) {
    auto it = sets.find(i);
    if (it == sets.begin()) return -1;
    return *(--it);
  };
  function<void(int)> recalc = [&](int i) {
    if (i == -1) return;
    auto it = sets.find(i);
    int nxt = *(++it);
    bool old = S[i].issub;
    S[i].issub = bs[i].is_subset(bs[nxt]);
    if (old && !S[i].issub)
      good.insert(i);
    else if (!old && S[i].issub)
      good.erase(i);
  };
  while (q--) {
    int i, l, r;
    scanf("%d %d %d", &i, &l, &r);
    --i;
    --l;
    int p = prev(i);
    sets.erase(i);
    recalc(p);
    bs[i] ^= pref[r] ^ pref[l];
    S[i].cnt = bs[i].count();
    sets.insert(i);
    recalc(prev(i));
    recalc(i);
    if (good.empty()) {
      printf("-1\n");
    } else {
      int x1 = *good.begin();
      int x2 = *(++sets.find(x1));
      Bitset<M> inters = bs[x1] & bs[x2];
      int y1 = (bs[x1] ^ inters).first();
      int y2 = (bs[x2] ^ inters).first();
      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);
    }
  }
}