#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);
    }
  }
}
