#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2005;
int numRow, numCol, numQuery;
bitset<MAX_N> arr[MAX_N];
int popcount[MAX_N];
bitset<MAX_N> base[11];
struct CustomCompare {
  bool operator()(const int x, const int y) const {
    return popcount[x] != popcount[y] ? popcount[x] < popcount[y] : x < y;
  }
};
set<int, CustomCompare> s;
set<pair<int, int>> answer;
bool check(const bitset<MAX_N> &a, const bitset<MAX_N> &b) {
  return ((a | b) != b);
}
pair<int, int> getAnswer(const bitset<MAX_N> &a, const bitset<MAX_N> &b) {
  int pos[2] = {-1, -1};
  for (int i = 1; i <= numCol && (pos[0] == -1 || pos[1] == -1); i++) {
    if (a[i] != b[i] && pos[a[i]] == -1) {
      pos[a[i]] = i;
    }
  }
  sort(pos, pos + 2);
  return make_pair(pos[0], pos[1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> numRow >> numCol >> numQuery;
  for (int i = 1; i <= numRow; i++) {
    s.insert(i);
  }
  base[0][0] = 1;
  for (int i = 0; i < 10; i++) {
    base[i + 1] = base[i] | (base[i] << (1 << i));
  }
  int row, left, right;
  while (numQuery--) {
    cin >> row >> left >> right;
    auto it = s.find(row);
    int posPre = -1, posNex = -1;
    auto temp = it;
    if (it != s.begin()) {
      temp--;
      posPre = *temp;
      answer.erase(make_pair(posPre, row));
    }
    temp = it;
    temp++;
    if (temp != s.end()) {
      posNex = *temp;
      answer.erase(make_pair(row, posNex));
    }
    if (posPre != -1 && posNex != -1 && check(arr[posPre], arr[posNex])) {
      answer.insert(make_pair(posPre, posNex));
    }
    s.erase(it);
    int length = right - left + 1;
    for (int i = 0; i <= 10; i++) {
      if ((length >> i) & 1) {
        arr[row] ^= (base[i] << left);
        left += (1 << i);
      }
    }
    popcount[row] = arr[row].count();
    it = s.lower_bound(row);
    if (it != s.end()) {
      if (it != s.begin()) {
        temp = it;
        temp--;
        answer.erase(make_pair(*temp, *it));
      }
    }
    s.insert(row);
    it = s.find(row);
    temp = it;
    if (it != s.begin()) {
      temp--;
      posPre = *temp;
      if (check(arr[posPre], arr[row])) {
        answer.insert(make_pair(posPre, row));
      }
    }
    temp = it;
    temp++;
    if (temp != s.end()) {
      posNex = *temp;
      if (check(arr[row], arr[posNex])) {
        answer.insert(make_pair(row, posNex));
      }
    }
    if (answer.empty()) {
      cout << -1 << '\n';
    } else {
      int x, y, u, v;
      tie(u, x) = *answer.begin();
      if (u > x) {
        swap(u, x);
      }
      tie(v, y) = getAnswer(arr[u], arr[x]);
      cout << u << ' ' << v << ' ' << x << ' ' << y << '\n';
    }
  }
  return 0;
}
