#include <bits/stdc++.h>
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const long long INF64 = (long long)2e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = std::acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
  T X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
const int MAXN = 1000005;
const int MAXV = 1 << 20;
int n, m, k;
int dr[4] = {0, 1, 0, -1};
int dc[4] = {-1, 0, 1, 0};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char S[MAXN];
int A[MAXN];
void solve() {
  scanf("%d", &n);
  return;
}
int main() {
  int a, b;
  scanf("%d%d%d", &a, &b, &n);
  for (int i = 0; i < n; i++) {
    int l, t;
    scanf("%d%d%d", &l, &t, &m);
    auto check = [=](int mid) {
      if ((long long)a + (long long)(mid - 1) * b > t) return false;
      if (m >= mid - l + 1) return true;
      long long init = (long long)a + (long long)(l - 1) * b;
      long long fin = (long long)a + (long long)(mid - 1) * b;
      return (init + fin) * (mid - l + 1) / 2 <= (long long)t * m;
    };
    int L = l, R = l + 1e6;
    int ans = -1;
    while (L <= R) {
      int mid = (L + R) / 2;
      if (check(mid)) {
        L = mid + 1;
        ans = mid;
      } else {
        R = mid - 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
