#include <bits/stdc++.h>
using namespace std;
long long A, B, n, r, l, t, m;
inline int Gint() {
  char ch;
  while (ch = getchar(), !('0' <= ch && ch <= '9'))
    ;
  int ret = ch - 48;
  while (ch = getchar(), ('0' <= ch && ch <= '9')) ret = ret * 10 + ch - 48;
  return ret;
}
inline long long S(long long r) {
  return (A + (l - 1) * B + A + (r - 1) * B) * (r - l + 1) / 2;
}
int main() {
  A = Gint();
  B = Gint();
  n = Gint();
  while (n--) {
    l = Gint();
    t = Gint();
    m = Gint();
    if (A + (l - 1) * B > t) {
      puts("-1");
      continue;
    }
    r = (t - A) / B + 1;
    if (r - l + 1 <= m) {
      printf("%I64d\n", r);
      continue;
    } else {
      if ((S(r) - 1) / m + 1 <= t) {
        printf("%I64d\n", r);
        continue;
      }
      long long L = l, R = r;
      while (L < R - 1) {
        long long mid = (L + R) >> 1;
        if ((S(mid) - 1) / m + 1 <= t)
          L = mid;
        else
          R = mid;
      }
      if ((S(R) - 1) / m + 1 <= t)
        printf("%I64d\n", R);
      else
        printf("%I64d\n", L);
    }
  }
  return 0;
}
