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 <class T>
void splitstr(const string &s, vector<T> &out) {
  istringstream in(s);
  out.clear();
  copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
static void redirect(int argc, const char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  if (argc > 1) {
    static filebuf f;
    f.open(argv[1], ios::in);
    cin.rdbuf(&f);
    if (!cin) {
      cerr << "Failed to open '" << argv[1] << "'" << endl;
      exit(1);
    }
  }
  if (argc > 2) {
    static filebuf f;
    f.open(argv[2], ios::out | ios::trunc);
    cout.rdbuf(&f);
    if (!cout) {
      cerr << "Failed to open '" << argv[2] << "'" << endl;
    }
  }
  cin.exceptions(ios::failbit);
}
class bits {
 public:
 private:
  size_t size;
  vector<uint32_t> words;
  static constexpr size_t W = sizeof(uint32_t) * CHAR_BIT;

 public:
  explicit bits(size_t size = 0);
  bool operator[](size_t idx) const;
  size_t count() const;
  void flip_range(size_t first, size_t last);
  pair<int, int> signature(const bits &other) const;
};
bits::bits(size_t size) : size(size), words((size + W - 1) / W) {}
bool bits::operator[](size_t idx) const {
  return (words[idx / W] >> (idx % W)) & 1;
}
size_t bits::count() const {
  size_t ans = 0;
  for (auto w : words)
    ans += (sizeof(w) <= sizeof(int) ? __builtin_popcount(w)
                                     : __builtin_popcountll(w));
  return ans;
}
void bits::flip_range(size_t first, size_t last) {
  if (first == last) return;
  size_t wfirst = first / W;
  size_t wlast = last / W;
  size_t ofirst = first % W;
  size_t olast = last % W;
  uint32_t sfirst = (uint32_t(1) << ofirst) - 1;
  uint32_t slast = (uint32_t(1) << olast) - 1;
  if (wfirst == wlast)
    words[wfirst] ^= slast - sfirst;
  else {
    words[wfirst] ^= ~sfirst;
    for (size_t i = wfirst + 1; i < wlast; i++) words[i] = ~words[i];
    if (slast) words[wlast] ^= slast;
  }
}
pair<int, int> bits::signature(const bits &other) const {
  int x = -1, y = -1;
  for (size_t i = 0; i < words.size(); i++) {
    uint32_t u = words[i];
    uint32_t v = other.words[i];
    uint32_t a = u & ~v;
    uint32_t b = v & ~u;
    if (a) x = i * W + __builtin_ctzll(a);
    if (b) y = i * W + __builtin_ctzll(b);
  }
  if (x != -1 && y != -1)
    return make_pair(x, y);
  else
    return make_pair(-1, -1);
}
struct certificate {
  int r1, r2;
  int c1, c2;
  bool operator<(const certificate &other) const {
    return tie(r1, r2, c1, c2) < tie(other.r1, other.r2, other.c1, other.c2);
  }
};
int main(int argc, const char **argv) {
  redirect(argc, argv);
  int R, C, Q;
  cin >> R >> C >> Q;
  vector<bits> rows(R, bits(C));
  set<pair<int, int> > order;
  set<certificate> certs;
  for (int i = 0; i < R; i++) order.emplace(0, i);
  auto join = [&](int r1, int r2) {
    pair<int, int> sig = rows[r1].signature(rows[r2]);
    if (sig.first != -1) {
      certificate cert{r1, r2, sig.first, sig.second};
      certs.insert(cert);
    }
  };
  auto split = [&](int r1, int r2) {
    pair<int, int> sig = rows[r1].signature(rows[r2]);
    if (sig.first != -1) {
      certificate cert{r1, r2, sig.first, sig.second};
      certs.erase(cert);
    }
  };
  for (int q = 0; q < Q; q++) {
    int a, l, r;
    cin >> a >> l >> r;
    a--;
    l--;
    int c = rows[a].count();
    auto old_pos = order.find(pair<int, int>(c, a));
    if (old_pos != order.begin()) split(prev(old_pos)->second, a);
    auto p = next(old_pos);
    if (p != order.end()) split(a, p->second);
    if (p != order.end() && old_pos != order.begin())
      join(prev(old_pos)->second, p->second);
    order.erase(old_pos);
    rows[a].flip_range(l, r);
    c = rows[a].count();
    auto new_pos = order.emplace(c, a).first;
    if (new_pos != order.begin()) join(prev(new_pos)->second, a);
    p = next(new_pos);
    if (p != order.end()) join(a, p->second);
    if (p != order.end() && new_pos != order.begin())
      split(prev(new_pos)->second, p->second);
    if (certs.empty())
      cout << "-1\n";
    else {
      auto c = *certs.begin();
      auto sig = rows[c.r1].signature(rows[c.r2]);
      if (c.r1 > c.r2) swap(c.r1, c.r2);
      if (c.c1 > c.c2) swap(c.c1, c.c2);
      cout << c.r1 + 1 << ' ' << c.c1 + 1 << ' ' << c.r2 + 1 << ' ' << c.c2 + 1
           << '\n';
    }
  }
  return 0;
}