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 cnt[65536];
const int N = 2005;
struct Bitset {
  unsigned a[65];
  Bitset() { memset(a, 0, sizeof(a)); }
  void set(int x) { a[x >> 5] |= 1u << (x & 31); }
  Bitset operator|(const Bitset &b) const {
    Bitset ans;
    for (int i = 0; i < 64; i += 4) {
      ans.a[i] = a[i] | b.a[i];
      ans.a[i + 1] = a[i + 1] | b.a[i + 1];
      ans.a[i + 2] = a[i + 2] | b.a[i + 2];
      ans.a[i + 3] = a[i + 3] | b.a[i + 3];
    }
    return ans;
  }
  Bitset operator^(const Bitset &b) const {
    Bitset ans;
    for (int i = 0; i < 64; i += 4) {
      ans.a[i] = a[i] ^ b.a[i];
      ans.a[i + 1] = a[i + 1] ^ b.a[i + 1];
      ans.a[i + 2] = a[i + 2] ^ b.a[i + 2];
      ans.a[i + 3] = a[i + 3] ^ b.a[i + 3];
    }
    return ans;
  }
  bool operator!=(const Bitset &b) const {
    Bitset ans;
    for (int i = 0; i < 64; i += 2)
      if (a[i] != b.a[i] || a[i + 1] != b.a[i + 1]) return 1;
    return 0;
  }
  int findfi() {
    for (int i = (int)(0); i <= (int)(63); i++)
      if (a[i])
        for (int j = (int)(0); j <= (int)(31); j++)
          if (a[i] & (1u << j)) return (i << 5) | j;
    assert(0);
  }
  int count() {
    int ans = 0;
    for (int i = 0; i < 64; i += 4) {
      ans += cnt[a[i] & 65535] + cnt[a[i] >> 16];
      ans += cnt[a[i + 1] & 65535] + cnt[a[i + 1] >> 16];
      ans += cnt[a[i + 2] & 65535] + cnt[a[i + 2] >> 16];
      ans += cnt[a[i + 3] & 65535] + cnt[a[i + 3] >> 16];
    }
    return ans;
  }
} b[N], a[N];
int n, m, Q, nxt[N];
set<pair<int, int> > S;
set<int> ans;
void insert(int x, int y) {
  nxt[x] = y;
  if ((a[x] | a[y]) != a[y]) ans.insert(x);
}
void erase(int x, int y) {
  if ((a[x] | a[y]) != a[y]) ans.erase(x);
}
void insert(int x) {
  pair<int, int> tmp(a[x].count(), x);
  set<pair<int, int> >::iterator pre, nxt;
  pre = nxt = S.lower_bound(tmp);
  if (nxt != S.begin()) {
    pre--;
    if (nxt != S.end()) {
      erase(pre->second, nxt->second);
      insert(x, nxt->second);
    }
    insert(pre->second, x);
  } else if (nxt != S.end())
    insert(x, nxt->second);
  S.insert(tmp);
}
void erase(int x) {
  pair<int, int> tmp(a[x].count(), x);
  S.erase(tmp);
  set<pair<int, int> >::iterator pre, nxt;
  pre = nxt = S.lower_bound(tmp);
  if (nxt != S.begin()) {
    pre--;
    erase(pre->second, x);
    if (nxt != S.end()) {
      insert(pre->second, nxt->second);
      erase(x, nxt->second);
    }
  } else if (nxt != S.end())
    erase(x, nxt->second);
}
int main() {
  for (int i = (int)(1); i <= (int)(65535); i++) cnt[i] = cnt[i / 2] + (i & 1);
  scanf("%d%d%d", &n, &m, &Q);
  for (int i = (int)(1); i <= (int)(m); i++) {
    b[i] = b[i - 1];
    b[i].set(i);
  }
  for (int i = (int)(1); i <= (int)(n); i++) insert(i);
  while (Q--) {
    int x, l, r;
    scanf("%d%d%d", &x, &l, &r);
    erase(x);
    a[x] = a[x] ^ b[l - 1] ^ b[r];
    insert(x);
    if (ans.empty())
      puts("-1");
    else {
      int x = *ans.begin(), y = nxt[x];
      Bitset tmp = a[x] | a[y];
      int p = (a[x] ^ tmp).findfi();
      int q = (a[y] ^ tmp).findfi();
      if (x > y) swap(x, y);
      if (p > q) swap(p, q);
      printf("%d %d %d %d\n", x, p, y, q);
    }
  }
}