#include <bits/stdc++.h>
using namespace std;
long long A, B, t, m, kar[2000005], skar[2000005];
int n, l;
bool check(int r) { return (kar[r] <= t && skar[r] - skar[l - 1] <= m * t); }
int main() {
  scanf("%I64d%I64d%d", &A, &B, &n);
  for (int i = 1; i <= 2000005 - 1; ++i) {
    kar[i] = min((long long)1000001, A + (i - 1) * B);
    skar[i] = skar[i - 1] + kar[i];
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d%I64d%I64d", &l, &t, &m);
    int sl = l, sr = 2000005 - 1, res = -1;
    while (sl <= sr) {
      int mid = (sl + sr) / 2;
      if (check(mid)) {
        if (mid > res) res = mid;
        sl = mid + 1;
      } else
        sr = mid - 1;
    }
    printf("%d\n", res);
  }
}
