#include <bits/stdc++.h>
using namespace std;
int n, m, q, cnt[2005];
unsigned long long x[2005][32], y[64][64];
set<pair<int, int>> s;
map<pair<int, int>, pair<int, int>> ss;
void check(int a, int b) {
  int ta = -1, tb = -1;
  for (int i = 0; i < 32; i++)
    if (x[a][i] != x[b][i]) {
      if (ta == -1) {
        unsigned long long tmp = x[a][i] & ~x[b][i];
        if (tmp) {
          ta = i * 64 + __builtin_ctzll(tmp);
          if (tb != -1) {
            ss[{a, b}] = {ta, tb};
            return;
          }
        }
      }
      if (tb == -1) {
        unsigned long long tmp = ~x[a][i] & x[b][i];
        if (tmp) {
          tb = i * 64 + __builtin_ctzll(tmp);
          if (ta != -1) {
            ss[{a, b}] = {ta, tb};
            return;
          }
        }
      }
    }
}
int main() {
  for (int i = 0; i < 64; i++)
    for (int j = i; j < 64; j++)
      for (int k = i; k <= j; k++) y[i][j] ^= 1ULL << k;
  scanf("%d%d%d", &n, &m, &q);
  s.emplace(-1, 0);
  for (int i = 1; i <= n; i++) s.emplace(0, i);
  s.emplace(64 * 32, n + 1);
  fill(x[n + 1], x[n + 1] + 32, ULLONG_MAX);
  while (q--) {
    int a, l, r;
    scanf("%d%d%d", &a, &l, &r);
    int from = l / 64;
    int to = r / 64;
    for (int i = from; i <= to; i++) {
      int ff = max(l, i * 64) % 64;
      int tt = min(r, i * 64 + 63) % 64;
      x[a][i] ^= y[ff][tt];
    }
    auto it = s.find({cnt[a], a});
    ss.erase({prev(it)->second, a});
    ss.erase({a, next(it)->second});
    check(prev(it)->second, next(it)->second);
    s.erase(it);
    cnt[a] = 0;
    for (int i = 0; i < 32; i++) cnt[a] += __builtin_popcountll(x[a][i]);
    it = s.emplace(cnt[a], a).first;
    ss.erase({prev(it)->second, next(it)->second});
    check(prev(it)->second, a);
    check(a, next(it)->second);
    if (ss.empty())
      puts("-1");
    else {
      int ta = ss.begin()->first.first;
      int tb = ss.begin()->first.second;
      int tc = ss.begin()->second.first;
      int td = ss.begin()->second.second;
      printf("%d %d %d %d\n", min(ta, tb), min(tc, td), max(ta, tb),
             max(tc, td));
    }
  }
}
