#include <bits/stdc++.h>
int a, b, n;
long long l, t, m;
long long low, high, s1, s2, mid;
bool judge(int mid, int s1, int s2) {
  if ((mid - l + 1) * (s1 + s2) / 2 <= t * m)
    return true;
  else
    return false;
}
void solve() {
  high = (t - a) / b + 1;
  low = l;
  while (low <= high) {
    mid = (high + low) / 2;
    s2 = a + (mid - 1) * b;
    if (judge(mid, s1, s2))
      low = mid + 1;
    else
      high = mid - 1;
  }
  printf("%lld\n", low - 1);
}
int main() {
  while (~scanf("%d%d%d", &a, &b, &n)) {
    while (n--) {
      scanf("%lld%lld%lld", &l, &t, &m);
      s1 = a + (l - 1) * b;
      if (s1 > t)
        printf("-1\n");
      else {
        solve();
      }
    }
  }
  return 0;
}
