#include <bits/stdc++.h>
using namespace std;
const long long MX = 2000010;
long long a, b, n, l, t, m, pocz, kon;
long long tab[MX], pref[MX];
bool dasie(long long x) {
  return (tab[x] <= t) && (pref[x] - pref[l - 1]) <= m * t;
}
int main() {
  scanf("%lld%lld%lld", &a, &b, &n);
  tab[1] = a;
  for (int i = 2; i <= 2000000; ++i) tab[i] = tab[i - 1] + b;
  pref[1] = tab[1];
  for (int i = 2; i <= 2000000; ++i) pref[i] = pref[i - 1] + tab[i];
  for (int i = 0; i < n; ++i) {
    scanf("%lld%lld%lld", &l, &t, &m);
    pocz = l;
    kon = 2000000;
    while (pocz < kon) {
      int s = (pocz + kon + 1) / 2;
      if (dasie(s))
        pocz = s;
      else
        kon = s - 1;
    }
    if (dasie(pocz))
      printf("%lld\n", pocz);
    else
      printf("-1\n");
  }
}
