#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return (a > b); }
int main() {
  int a, b, n, l, t, m, x, ans, r;
  long long cek;
  scanf("%d %d %d", &a, &b, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &l, &t, &m);
    if (t < a + (long long)(l - 1) * b)
      printf("-1\n");
    else {
      x = 1;
      ans = l;
      while (x > 0) {
        r = ans + x;
        cek = ((a + (long long)(r - 1) * b + a + (long long)(l - 1) * b) *
               (r - l + 1)) /
              2;
        cek = max(cek / m + (cek % m == 0 ? 0 : 1), a + (long long)(r - 1) * b);
        if (cek <= t)
          ans += x, x *= 2;
        else
          x /= 2;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
