import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;
public class TaskA {
private final InputReader reader;
private final OutputWriter writer;
public TaskA(InputReader reader, OutputWriter writer) {
this.reader = reader;
this.writer = writer;
}
public static void main
(String[] args
) { InputReader reader
= new InputReader
(System.
in); OutputWriter writer
= new OutputWriter
(System.
out); new TaskA(reader, writer).run();
writer.writer.flush();
}
public void run() {
long A = reader.nextInt();
long B = reader.nextInt();
int n = reader.nextInt();
for (int i = 0; i < n; i++) {
int l = reader.nextInt();
int t = reader.nextInt();
int m = reader.nextInt();
long a
= 0, b
= 2 * Math.
max(t, m
) + 1; while (b - a > 1) {
long q = (a + b) / 2;
if (A + (l + q - 2) * 1l * B <= t && (A + (l - 1) * 1l * B) * 1l * q + B * 1l * q * (q - 1) / 2 <= m * 1l * t)
a = q;
else
b = q;
}
writer.printf("%d\n", (a == 0) ? -1 : l + a - 1);
}
}
static class InputReader {
tokenizer = null;
}
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
}
}
return tokenizer.nextToken();
}
public int nextInt() {
}
public double nextDouble() {
return Double.
parseDouble(next
()); }
public long nextLong() {
return Long.
parseLong(next
()); }
}
static class OutputWriter {
}
}
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC5Mb2NhbGU7CmltcG9ydCBqYXZhLnV0aWwuU3RyaW5nVG9rZW5pemVyOwoKcHVibGljIGNsYXNzIFRhc2tBIHsKICAgIHByaXZhdGUgZmluYWwgSW5wdXRSZWFkZXIgcmVhZGVyOwogICAgcHJpdmF0ZSBmaW5hbCBPdXRwdXRXcml0ZXIgd3JpdGVyOwoKICAgIHB1YmxpYyBUYXNrQShJbnB1dFJlYWRlciByZWFkZXIsIE91dHB1dFdyaXRlciB3cml0ZXIpIHsKICAgICAgICB0aGlzLnJlYWRlciA9IHJlYWRlcjsKICAgICAgICB0aGlzLndyaXRlciA9IHdyaXRlcjsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgSW5wdXRSZWFkZXIgcmVhZGVyID0gbmV3IElucHV0UmVhZGVyKFN5c3RlbS5pbik7CiAgICAgICAgT3V0cHV0V3JpdGVyIHdyaXRlciA9IG5ldyBPdXRwdXRXcml0ZXIoU3lzdGVtLm91dCk7CiAgICAgICAgbmV3IFRhc2tBKHJlYWRlciwgd3JpdGVyKS5ydW4oKTsKICAgICAgICB3cml0ZXIud3JpdGVyLmZsdXNoKCk7CiAgICB9CgogICAgcHVibGljIHZvaWQgcnVuKCkgewogICAgICAgIGxvbmcgQSA9IHJlYWRlci5uZXh0SW50KCk7CiAgICAgICAgbG9uZyBCID0gcmVhZGVyLm5leHRJbnQoKTsKICAgICAgICBpbnQgbiA9IHJlYWRlci5uZXh0SW50KCk7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaW50IGwgPSByZWFkZXIubmV4dEludCgpOwogICAgICAgICAgICBpbnQgdCA9IHJlYWRlci5uZXh0SW50KCk7CiAgICAgICAgICAgIGludCBtID0gcmVhZGVyLm5leHRJbnQoKTsKICAgICAgICAgICAgbG9uZyBhID0gMCwgYiA9IDIgKiBNYXRoLm1heCh0LCBtKSArIDE7CiAgICAgICAgICAgIHdoaWxlIChiIC0gYSA+IDEpIHsKICAgICAgICAgICAgICAgIGxvbmcgcSA9IChhICsgYikgLyAyOwogICAgICAgICAgICAgICAgaWYgKEEgKyAobCArIHEgLSAyKSAqIDFsICogQiA8PSB0ICYmIChBICsgKGwgLSAxKSAqIDFsICogQikgKiAxbCAqIHEgKyBCICogMWwgKiBxICogKHEgLSAxKSAvIDIgPD0gbSAqIDFsICogdCkKICAgICAgICAgICAgICAgICAgICBhID0gcTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBiID0gcTsKICAgICAgICAgICAgfQogICAgICAgICAgICB3cml0ZXIucHJpbnRmKCIlZFxuIiwgKGEgPT0gMCkgPyAtMSA6IGwgKyBhIC0gMSk7CiAgICAgICAgfQogICAgfQoKCiAgICBzdGF0aWMgY2xhc3MgSW5wdXRSZWFkZXIgewogICAgICAgIHB1YmxpYyBCdWZmZXJlZFJlYWRlciByZWFkZXI7CiAgICAgICAgcHVibGljIFN0cmluZ1Rva2VuaXplciB0b2tlbml6ZXI7CgogICAgICAgIHB1YmxpYyBJbnB1dFJlYWRlcihJbnB1dFN0cmVhbSBzdHJlYW0pIHsKICAgICAgICAgICAgcmVhZGVyID0gbmV3IEJ1ZmZlcmVkUmVhZGVyKG5ldyBJbnB1dFN0cmVhbVJlYWRlcihzdHJlYW0pLCAzMjc2OCk7CiAgICAgICAgICAgIHRva2VuaXplciA9IG51bGw7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgU3RyaW5nIG5leHQoKSB7CiAgICAgICAgICAgIHdoaWxlICh0b2tlbml6ZXIgPT0gbnVsbCB8fCAhdG9rZW5pemVyLmhhc01vcmVUb2tlbnMoKSkgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICB0b2tlbml6ZXIgPSBuZXcgU3RyaW5nVG9rZW5pemVyKHJlYWRlci5yZWFkTGluZSgpKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKElPRXhjZXB0aW9uIGUpIHsKICAgICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgUnVudGltZUV4Y2VwdGlvbihlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gdG9rZW5pemVyLm5leHRUb2tlbigpOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIGludCBuZXh0SW50KCkgewogICAgICAgICAgICByZXR1cm4gSW50ZWdlci5wYXJzZUludChuZXh0KCkpOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIGRvdWJsZSBuZXh0RG91YmxlKCkgewogICAgICAgICAgICByZXR1cm4gRG91YmxlLnBhcnNlRG91YmxlKG5leHQoKSk7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgbG9uZyBuZXh0TG9uZygpIHsKICAgICAgICAgICAgcmV0dXJuIExvbmcucGFyc2VMb25nKG5leHQoKSk7CiAgICAgICAgfQogICAgfQoKICAgIHN0YXRpYyBjbGFzcyBPdXRwdXRXcml0ZXIgewogICAgICAgIHB1YmxpYyBQcmludFdyaXRlciB3cml0ZXI7CgogICAgICAgIE91dHB1dFdyaXRlcihPdXRwdXRTdHJlYW0gc3RyZWFtKSB7CiAgICAgICAgICAgIHdyaXRlciA9IG5ldyBQcmludFdyaXRlcihzdHJlYW0pOwogICAgICAgIH0KCiAgICAgICAgcHVibGljIHZvaWQgcHJpbnRmKFN0cmluZyBmb3JtYXQsIE9iamVjdC4uLiBhcmdzKSB7CiAgICAgICAgICAgIHdyaXRlci5wcmludChTdHJpbmcuZm9ybWF0KExvY2FsZS5FTkdMSVNILCBmb3JtYXQsIGFyZ3MpKTsKICAgICAgICB9CiAgICB9Cn0K