#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<math.h>
#include<memory.h>
#include<sstream>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)
#define inf (0x7fffffff)
#define mp make_pair
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define All(a) a.begin(), a.end()

typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef   double ld;

void print(int a[],int n){
    rep(i,n)cout<<a[i]<<" ";
    cout<<endl;
}

ll a,b,n;
ll l,t,m;
bool can(ll mid){
    ll sum1=((mid*(mid+1))/2);
    ll sum2=((l*(l-1))/2);
    ll sum=sum1-sum2;
    sum*=b;
    if( a+ b*(mid-1)  > t)return 0;
    return sum <= m*t;
}

int main(){
    fastIO;
    //read;
    cin>>a>>b>>n;
    while(n--){
        cin>>l>>t>>m;
        ll lft=l ,r=1000000000 , res=-1 , mid;
        while( lft<= r){
            mid=(lft+r)>>1;
            if( can (mid )) res=mid , lft=mid+1;
            else r=mid-1;
        }
        cout<<res<<endl;
    }
    return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<math.h>
#include<memory.h>
#include<sstream>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)
#define inf (0x7fffffff)
#define mp make_pair
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define All(a) a.begin(), a.end()

typedef  long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef   double ld;

void print(int a[],int n){
    rep(i,n)cout<<a[i]<<" ";
    cout<<endl;
}

ll a,b,n;
ll l,t,m;
bool can(ll mid){
    ll sum1=((mid*(mid+1))/2);
    ll sum2=((l*(l-1))/2);
    ll sum=sum1-sum2;
    sum*=b;
    sum+=(mid-l+1)*a;
    if( a+ b*(mid-1)  > t)return 0;
    return sum <= m*t;
}

int main(){
    fastIO;
    //read;
    cin>>a>>b>>n;
    while(n--){
        cin>>l>>t>>m;
        ll lft=l ,r=1000000000 , res=-1 , mid;
        while( lft<= r){
            mid=(lft+r)>>1;
            if( can (mid )) res=mid , lft=mid+1;
            else r=mid-1;
        }
        cout<<res<<endl;
    }
    return 0;
}


#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

LL a, b, l, t, m;

bool check(LL r)
{
	LL beg = a + b*(l - 1);
	LL end = a + b*(r - 1);
	LL len = (r - l + 1);

	LL sum = (beg + end)*len / 2;

	return r < l || end <= t && sum <= t*min(len,m);
}

int get()
{
	LL ll = 0, rr = INF;

	while (ll < rr - 1)
	{
		LL mm = (ll + rr) / 2;
		if (check(mm))
			ll = mm;
		else
			rr = mm;
	}
	return ll;
}

void solve()
{
	int n;
	cin >> a >> b >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> l >> t >> m;
		int a = get();
		if (a < l)
			cout << -1 << endl;
		else
			cout << a << endl;
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
#endif


#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

LL a, b, l, t, m;

bool check(LL r)
{
	LL beg = a + b*(l - 1);
	LL end = a + b*(r - 1);
	LL len = (r - l + 1);

	LL sum = (beg + end)*len / 2;

	return end <= t && sum <= t*min(len,m);
}

int get()
{
	LL ll = 0, rr = INF;

	while (ll < rr - 1)
	{
		LL mm = (ll + rr) / 2;
		if (check(mm))
			ll = mm;
		else
			rr = mm;
	}
	return ll;
}

void solve()
{
	int n;
	cin >> a >> b >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> l >> t >> m;
		int a = get();
		if (a < l)
			cout << -1 << endl;
		else
			cout << a << endl;
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
#endif


#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

LL a, b, l, t, m;

bool check(LL r)
{
	return a+b*(r - 1) <= t && (2*a + b*(l+r-2))*(r-l+1)/2 <= t*min(m,(r-l+1));
}

int get()
{
	LL ll = 0, rr = INF;

	while (ll < rr - 1)
	{
		LL mm = (ll + rr) / 2;
		if (check(mm))
			ll = mm;
		else
			rr = mm;
	}
	return ll;
}

void solve()
{
	int n;
	cin >> a >> b >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> l >> t >> m;
		int a = get();
		if (a < l)
			cout << -1 << endl;
		else
			cout << a << endl;
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
#endif


#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

LL a, b, l, t, m;

bool check(LL r)
{
	return a+b*r <= t && (2*a + b*(l+r-1))*(r-l+2)/2 <= t*min(m,(r-l+2));
}

int get()
{
	LL ll = 0, rr = INF;

	while (ll < rr - 1)
	{
		LL mm = (ll + rr) / 2;
		if (check(mm))
			ll = mm;
		else
			rr = mm;
	}
	return ll+1;
}

void solve()
{
	int n;
	cin >> a >> b >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> l >> t >> m;
		int a = get();
		if (a < l)
			cout << -1 << endl;
		else
			cout << a << endl;
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
#endif


#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

LL a, b, l, t, m;
LL arit(int x)
{
	return (a + a*b*(x - 1))*x / 2;
}

bool check(LL r)
{
	if ((a + (double)a*b*(r - 1))*r / 2 > 1e18)
		return false;
	return arit(r) - arit(l) <= t*min(m,(r-l+1)) && a+b*(r - 1) <= t;
}

int get()
{
	LL ll = 0, rr = INF;

	while (ll < rr - 1)
	{
		LL mm = (ll + rr) / 2;
		if (check(mm))
			ll = mm;
		else
			rr = mm;
	}
	return ll;
}

void solve()
{
	int n;
	cin >> a >> b >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> l >> t >> m;
		int a = get();
		if (a < l)
			cout << -1 << endl;
		else
			cout << a << endl;
	}
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	ios_base::sync_with_stdio(false);
	solve();

	return 0;
}
#endif


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(LL l,LL x,int id){
    LL sum = ((1LL*A +1LL*(l-1)*B+1LL*A+1LL*(x-1)*B))/2LL *1LL*(x-l+1);
   // printf("---id = %d sum = %I64d\n",id,sum);
    return 1LL*m[id]*t[id] >= sum && (1LL*A+1LL*(x-1)*B) <= t[id];
}

void solve(){
    LL lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = 1LL*l[i];ub = 1LL*1e6,flag = 0;
        for(int k = 0;k <= 100;k++){
            mid = (lb+ub)/2LL;
            if(ok(l[i],mid,i)){
                flag = 1;
                lb = mid+1;
            }
            else ub = mid-1;
          //  printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
        }
        if(flag && mid >= l[i]) printf("%I64d\n",ub);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(int l,int r,int id){
    LL x = 1LL*A + 1LL*(l-1)*B;
    LL y = 1LL*A + 1LL*(r-1)*B;
    LL sum = 1LL*(x+y)*(r-l+1)/2;
    //printf("---id = %d sum = %I64d\n",id,sum);
    return 1LL*m[id]*t[id] >= sum && y <= t[id];
}

void solve(){
    int lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = l[i];ub = 1e6,flag = 0;
        int ans = 0;
        for(int k = 0;k <= 100;k++){
            mid = lb + (ub-lb)/2;
            if(ok(l[i],mid,i)){
                flag = 1;
                lb = mid+1;
                ans = max(ans,mid);
            }
            else ub = mid-1;
           // printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
        }
        if(flag && ans >= l[i]) printf("%d\n",ans);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(LL l,LL x,int id){
    LL sum = ((1LL*A +1LL*(l-1)*B+1LL*A+1LL*(x-1)*B))/2LL *1LL*(x-l+1);
    //printf("---id = %d sum = %I64d\n",id,sum);
    return 1LL*m[id]*t[id] >= sum && (1LL*A+1LL*(x-1)*B) <= t[id];
}

void solve(){
    LL lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = 1LL*l[i];ub = 1LL*1e6,flag = 0;
        LL ans = -1;
        for(int k = 0;k <= 100;k++){
            mid = 1LL*lb + (ub-lb)/2LL;
            if(ok(l[i],mid,i)){
                flag = 1;
                lb = mid+1;
                ans = max(ans,mid);
            }
            else ub = mid-1;
           // printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
        }
        if(flag && ans >= l[i]) printf("%I64d\n",ans);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(LL l,LL x,int id){
    LL sum = (1LL*(1LL*A +(l-1)*B+1LL*A+(x-1)*B)*(x-l+1))/2LL;
    return 1LL*m[id]*t[id] >= sum && (A+(x-1)*B) <= t[id];
}

void solve(){
    LL lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = l[i];ub = 1LL*m[i]*t[i],flag = 0;
        for(int k = 0;k <= 100;k++){
            mid = (lb+ub)/2;
            if(ok(lb,mid,i)){
                flag = 1;
                lb = mid+1;
            }
            else ub = mid-1;
            //printf("i = %d lb = %d ub = %d mid = %d\n",i,lb,ub,mid);
        }
        if(flag && mid >= l[i]) printf("%I64d\n",mid);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(LL l,LL x,int id){
    LL sum = ((1LL*A +1LL*(l-1)*B+1LL*A+1LL*(x-1)*B))/2LL *1LL*(x-l+1);
   // printf("---id = %d sum = %I64d\n",id,sum);
    return 1LL*m[id]*t[id] >= sum && (1LL*A+1LL*(x-1)*B) <= t[id];
}

void solve(){
    LL lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = 1LL*l[i];ub = 1LL*1e6,flag = 0;
        for(int k = 0;k <= 100;k++){
            mid = lb+ub/2LL;
            if(ok(l[i],mid,i)){
                flag = 1;
                lb = mid+1;
            }
            else ub = mid-1;
          //  printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
        }
        if(flag && ub >= l[i]) printf("%I64d\n",ub);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
int n,A,B;
const int maxn = 1e5+5;
const int INF = (1<<30)-1;
int l[maxn],t[maxn],m[maxn];

int ok(LL l,LL x,int id){
    LL sum = ((1LL*A +1LL*(l-1)*B+1LL*A+1LL*(x-1)*B))/2LL *1LL*(x-l+1);
    //printf("---id = %d sum = %I64d\n",id,sum);
    return 1LL*m[id]*t[id] >= sum && (1LL*A+1LL*(x-1)*B) <= t[id];
}

void solve(){
    LL lb,ub,mid;
    int flag;
    for(int i = 1;i <= n;i++){
        lb = 1LL*l[i];ub = 1LL*1e6,flag = 0;
        for(int k = 0;k <= 100;k++){
            mid = 1LL*lb + (ub-lb)/2LL;
            if(ok(l[i],mid,i)){
                flag = 1;
                lb = mid+1;
            }
            else ub = mid-1;
           // printf("i = %d lb = %I64d ub = %I64d mid = %I64d\n",i,lb,ub,mid);
        }
        if(flag && ub >= l[i]) printf("%I64d\n",ub);
        else puts("-1");
    }
}

int main(){
    while(scanf("%d %d %d",&A,&B,&n) != EOF){
        for(int i = 1;i <= n;i++) scanf("%d %d %d",&l[i],&t[i],&m[i]);
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=100100,inf=1e9;
int a,b,n;
inline int cal(int x){return a+(x-1)*b;}
inline int cal(int l,int r){return (cal(l)+cal(r))*(r-l+1)/2;}
//x+2x+...+lx
inline bool check(int l,int r,int t,int m)
{
	if(cal(r)>t) return 0;
	m=min(m,r-l+1);
	int get=cal(l,r)/m;
	return get<=t;
}
inline int getans(int l,int t,int m)
{
	int L=l,R=2e6,ans=l;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(check(l,mid,t,m)) ans=max(ans,mid),L=mid+1;
		else R=mid-1;
	}
	return ans;
}
signed main()
{
	cin>>a>>b>>n;
	while(n--)
	{
		int l,t,m;scanf("%lld%lld%lld",&l,&t,&m);
		if(cal(l)>t) puts("-1");
		else printf("%lld\n",getans(l,t,m));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=100100,inf=1e9;
int a,b,n;
inline int cal(int x){return a+(x-1)*b;}
inline int cal(int l,int r){return (cal(l)+cal(r))*(r-l+1)/2;}
//x+2x+...+lx
inline bool check(int l,int r,int t,int m)
{
	int get=cal(l,r)/m;
	return get<=t;
}
inline int getans(int l,int t,int m)
{
	int L=l,R=2e6,ans=l;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(check(l,mid,t,m)) ans=max(ans,mid),L=mid+1;
		else R=mid-1;
	}
	return ans;
}
signed main()
{
	cin>>a>>b>>n;
	while(n--)
	{
		int l,t,m;scanf("%lld%lld%lld",&l,&t,&m);
		if(cal(l)>t) puts("-1");
		else printf("%lld\n",getans(l,t,m));
	}
	return 0;
}
/*
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
2 3 4 5 6 7 8 9
*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=100100,inf=1e9;
int a,b,n;
inline int cal(int x){return a+(x-1)*b;}
inline int cal(int l,int r){return (cal(l)+cal(r))*(r-l+1)/2;}
//x+2x+...+lx
inline bool check(int l,int r,int t,int m)
{
	if(cal(r)>t) return 0;
	int get=cal(l,r)/m;
	return get<=t;
}
inline int getans(int l,int t,int m)
{
	int L=l,R=2e6,ans=l;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(check(l,mid,t,m)) ans=max(ans,mid),L=mid+1;
		else R=mid-1;
	}
	return ans;
}
signed main()
{
	cin>>a>>b>>n;
	while(n--)
	{
		int l,t,m;scanf("%lld%lld%lld",&l,&t,&m);
		if(cal(l)>t) puts("-1");
		else printf("%lld\n",getans(l,t,m));
	}
	return 0;
}
/*
1 5 2
1 5 10
2 7 4
*/


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=100100,inf=1e9;
int a,b,n;
inline int cal(int x){return a+(x-1)*b;}
inline int cal(int l,int r){return (cal(l)+cal(r))*(r-l+1)/2;}
//x+2x+...+lx
inline bool check(int l,int r,int t,int m){return cal(l,r)<=m*t&&cal(r)<=t;}
inline int getans(int l,int t,int m)
{
	int L=l,R=2e6,ans=l;
	while(L<=R)
	{
		int mid=(L+R)>>1;
		if(check(l,mid,t,m)) ans=max(ans,mid),L=mid+1;
		else R=mid-1;
	}
	return ans;
}
signed main()
{
	cin>>a>>b>>n;
	while(n--)
	{
		int l,t,m;scanf("%lld%lld%lld",&l,&t,&m);
		if(cal(l)>t) puts("-1");
		else printf("%lld\n",getans(l,t,m));
	}
	return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

int a, b;

ll max_value (int valor){

    ll lo = 0, hi = 1e16;

    while(lo < hi){
        ll mid = (lo + hi) / 2;

        ll cur = 1LL * a + 1LL * b * mid - b;

        //cout << mid << " " << cur << " " << valor << endl;

        if(cur > valor)
            hi = mid ;
        else{

            lo = mid + 1;
        }
    }

    ll cur = 1LL * a + 1LL * b * lo - b;
    if(cur > valor)
        return lo - 1;

    return lo;

}

ll get_s(ll mid, ll l){
            ll sum = 1LL * (mid - l + 1) * a;
            ll aux = 1LL * (mid - 1) * (mid - 2) / 2;
            ll aux2 = 1LL * (l - 2) * (l - 3) / 2;

            if(aux2 > 0)
                aux -= aux2;
            if( aux < 0)
                aux = 0;

            sum = sum + aux * b;
            return sum;
}
int main()
{
    int n; cin >> a >> b >> n;

    for(int i = 0 ; i < n; i++)
    {

        int l, t, m; cin >> l >> t >> m;

        ll lo = l, hi = max_value(t);

       // cout << lo << " " << hi << endl;

        ll ans = -1;

        if(hi < l){
            cout << -1 << '\n';
            continue;
        }

        while(lo < hi){
            ll mid = (lo + hi) / 2;

            ll sum = get_s(mid, l);

            if(sum > 1LL * m * t){
                hi = mid;
            }else{
                ans = max(ans, mid);
                lo = mid + 1;
            }
        }

        if(get_s(lo, l) > 1LL * m * t)
            cout << lo - 1 << '\n';
        else
            cout << lo << '\n';

    }

    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

typedef long long ll;

int a, b;

ll max_value (int valor){

    ll lo = 0, hi = 1e6;

    while(lo < hi){
        ll mid = (lo + hi) / 2;

        ll cur = 1LL * a + 1LL * b * mid - b;

        //cout << mid << " " << cur << " " << valor << endl;

        if(cur > valor)
            hi = mid ;
        else{

            lo = mid + 1;
        }
    }

    ll cur = 1LL * a + 1LL * b * lo - b;
    if(cur > valor)
        return lo - 1;

    return lo;

}

ll get_s(ll mid, ll l){
            ll sum = 1LL * (mid - l + 1) * a;
            ll aux = 1LL * (mid) * (mid - 1) / 2;
            ll aux2 = 1LL * (l - 1) * (l - 2) / 2;

            if(aux2 > 0)
                aux -= aux2;
            if( aux < 0)
                aux = 0;

            sum = sum + aux * b;
            return sum;
}
int main()
{
    int n; scanf("%d %d %d", &a, &b, &n);

    for(int i = 0 ; i < n; i++)
    {

        int l, t, m; scanf("%d %d %d", &l, &t, &m);

        ll lo = l, hi = max_value(t);

       // cout << lo << " " << hi << endl;

        ll ans = -1;

        if(hi < l){
            printf("-1\n");
            continue;
        }

        while(lo < hi){
            ll mid = (lo + hi) / 2;

            ll sum = get_s(mid, l);

            if(sum > 1LL * m * t){
                hi = mid;
            }else{
                ans = max(ans, mid);
                lo = mid + 1;
            }
        }

        if(get_s(lo, l) > 1LL * m * t)
            printf("%d\n", lo - 1);
        else
            printf("%d\n", lo);

    }

    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

int a, b;

ll max_value (int valor){

    ll lo = 0, hi = 1e16;
    ll ans = 0;

    while(lo <= hi){
        ll mid = (lo + hi) / 2;

        ll cur = 1LL * a + 1LL * b * mid - b;

        //cout << mid << " " << cur << " " << valor << endl;

        if(cur > valor)
            hi = mid - 1 ;
        else{

            ans = max(ans, mid);
             lo = mid + 1;
        }
    }

    return ans;

}

int main()
{
    int n; cin >> a >> b >> n;

    for(int i = 0 ; i < n; i++)
    {
        int l, t, m; cin >> l >> t >> m;

        ll lo = l, hi = max_value(t);

       // cout << lo << " " << hi << endl;

        ll ans = -1;

        if(hi < l){
            cout << -1 << '\n';
            continue;
        }

        while(lo <= hi){
            ll mid = (lo + hi) / 2;

            ll sum = 1LL * (mid - l + 1) * a;
            ll aux = 1LL * (mid - 1) * (mid - 2) / 2;
            ll aux2 = 1LL * (l - 2) * (l - 3) / 2;

            if(aux2 > 0)
                aux -= aux2;
            if( aux < 0)
                aux = 0;

            sum = sum + aux * b;

            if(sum > 1LL * m * t){
                hi = mid - 1;
            }else{
                ans = max(ans, mid);
                lo = mid + 1;
            }
        }

        cout << ans << '\n';
    }

    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

int a, b;

ll max_value (int valor){

    ll lo = 0, hi = 1e15;
    ll ans = 0;

    while(lo <= hi){
        ll mid = (lo + hi) / 2;

        ll cur = 1LL * a + 1LL * b * mid - b;

        //cout << mid << " " << cur << " " << valor << endl;

        if(cur > valor)
            hi = mid - 1 ;
        else{

            ans = max(ans, mid);
             lo = mid + 1;
        }
    }

    return ans;

}

int main()
{
    int n; cin >> a >> b >> n;

    for(int i = 0 ; i < n; i++)
    {
        int l, t, m; cin >> l >> t >> m;

        ll lo = l, hi = max_value(t);

       // cout << lo << " " << hi << endl;

        ll ans = -1;

        if(hi < l){
            cout << -1 << '\n';
            continue;
        }

        while(lo <= hi){
            ll mid = (lo + hi) / 2;

            ll sum = 1LL * (mid - l + 1) * a;
            ll aux = 1LL * (mid - 1) * (mid - 2) / 2;
            ll aux2 = 1LL * (l - 2) * (l - 3) / 2;

            if(aux2 > 0)
                aux -= aux2;
            if( aux < 0)
                aux = 0;

            sum = sum + aux * b;

            if(sum > 1LL * m * t){
                hi = mid - 1;
            }else{
                ans = max(ans, mid);
                lo = mid + 1;
            }
        }

        cout << ans << '\n';
    }

    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;

int a, b;

ll max_value (int valor){

    ll lo = 0, hi = 1e15;
    ll ans = 0;

    while(lo <= hi){
        ll mid = (lo + hi) / 2;

        ll cur = 1LL * a + 1LL * b * mid - b;

        //cout << mid << " " << cur << " " << valor << endl;

        if(cur > valor)
            hi = mid - 1 ;
        else{

            ans = max(ans, mid);
             lo = mid + 1;
        }
    }

    return ans;

}

int main()
{
    int n; cin >> a >> b >> n;

    for(int i = 0 ; i < n; i++)
    {
        int l, t, m; cin >> l >> t >> m;

        ll lo = l, hi = max_value(t);

       // cout << lo << " " << hi << endl;

        ll ans = -1;

        if(hi < l){
            cout << -1 << '\n';
            continue;
        }

        while(lo <= hi){
            ll mid = (lo + hi) / 2;

            ll sum = 1LL * (mid - l + 1) * a;
            ll aux = 1LL * (mid - 1) * (mid - 2) / 2;
            aux -= 1LL * (l - 2) * (l - 3) / 2;

            sum = sum + aux * b;

            if(sum > 1LL * m * t){
                hi = mid - 1;
            }else{
                ans = max(ans, mid);
                lo = mid + 1;
            }
        }

        cout << ans << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a, b, n;

long long get_sum(long long l) {
    if (l == 0)
        return 0;
    return a * l + (l * (l - 1) / 2) * b;
}

long long get_at(long long l) {
    return a + (l - 1) * b;
}

long long calc(long long l, long long r, long long m) {
    m = min(m, r - l + 1);
    if (m == 1) {
        return get_sum(r) - get_sum(l - 1);
    }
    long long sum = get_sum(r) - get_sum(l - 1);

    sum = sum / m + (sum % m > 0);

    long long rv = get_at(r);

    return max(rv, sum);
}

int main() {
    cin >> a >> b >> n;
    while (n--) {
        int l, t, m;
        cin >> l >> t >> m;
        int s = l;
        int e = 2e9;
        int ans = -1;

        while (s <= e) {
            int md = s + (e - s) / 2;
            long long cnt = calc(l, md, m);
            if (cnt <= t) {
                ans = md;
                s = md + 1;
            } else {
                e = md - 1;
            }

        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a, b, n;

long long get_sum(long long l) {
    if (l == 0)
        return 0;
    long long res = 0;
    if (l % 2 == 0)
        res = l / 2 * (l - 1);
    else
        res = (l - 1) / 2 * l;
    return a * l + res * b;
}

long long get_at(long long l) {
    return a + (l - 1) * b;
}

long long calc(long long l, long long r, long long m) {
    m = min(m, r - l + 1);
    if (m == 1) {
        return get_sum(r) - get_sum(l - 1);
    }
    long long sum = get_sum(r) - get_sum(l - 1);

    sum = sum / m + (sum % m > 0);

    long long rv = get_at(r);

    return max(rv, sum);
}

int main() {
    cin >> a >> b >> n;
    while (n--) {
        int l, t, m;
        cin >> l >> t >> m;
        int s = l;
        int e = 1e6;
        int ans = -1;

        while (s <= e) {
            int md = s + (e - s) / 2;
            long long cnt = calc(l, md, m);
            if (cnt <= t) {
                ans = md;
                s = md + 1;
            } else {
                e = md - 1;
            }

        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a, b, n;

long long get_sum(long long l) {
    if (l == 0)
        return 0;
    return a * l + (l * (l - 1) / 2) * b;
}

long long get_at(long long l) {
    return a + (l - 1) * b;
}

long long calc(long long l, long long r, long long m) {
    m = min(m, r - l + 1);
    if (m == 1) {
        return get_sum(r) - get_sum(l - 1);
    }
    long long sum = get_sum(r - 1) - get_sum(l - 1);

    sum = sum / (m - 1) + (sum % (m - 1) > 0);

    long long rv = get_at(r);

    return max(rv, sum);
}

int main() {
    cin >> a >> b >> n;
    while (n--) {
        int l, t, m;
        cin >> l >> t >> m;
        int s = l;
        int e = 2e9;
        int ans = -1;
        while (s <= e) {
            int md = s + (e - s) / 2;
            long long cnt = calc(l, md, m);
            if (cnt <= t) {
                ans = md;
                s = md + 1;
            } else {
                e = md - 1;
            }

        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a, b, n;

long long get_sum(long long l) {
    if (l == 0)
        return 0;
    return a * l + (l * (l - 1) / 2) * b;
}

long long get_at(long long l) {
    return a + (l - 1) * b;
}

long long calc(long long l, long long r, long long m) {
    m = min(m, r - l + 1);
    if (m == 1) {
        return get_sum(r) - get_sum(l - 1);
    }
    long long sum = get_sum(r - 1) - get_sum(l - 1);

    sum = sum / (m - 1) + (sum % (m - 1) > 0);

    long long rv = get_at(r);

    return max(rv, sum);
}

int main() {
    cin >> a >> b >> n;
    while (n--) {
        int l, t, m;
        cin >> l >> t >> m;
        int s = l;
        int e = 1e9;
        int ans = -1;
        while (s <= e) {
            int md = s + (e - s) / 2;
            long long cnt = calc(l, md, m);
            if (cnt <= t) {
                ans = md;
                s = md + 1;
            } else {
                e = md - 1;
            }

        }
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a, b, n;

long long get_sum(long long l) {
    if (l == 0)
        return 0;
    long long res = 0;
    if (l % 2 == 0)
        res = l / 2 * (l - 1);
    else
        res = (l - 1) / 2 * l;
    return a * l + res * b;
}

long long get_at(long long l) {
    return a + (l - 1) * b;
}

long long calc(long long l, long long r, long long m) {
    m = min(m, r - l + 1);
    if (m == 1) {
        return get_sum(r) - get_sum(l - 1);
    }
    long long sum = get_sum(r) - get_sum(l - 1);

    sum = sum / m + (sum % m > 0);

    long long rv = get_at(r);

    return max(rv, sum);
}

int main() {
    cin >> a >> b >> n;
    while (n--) {
        int l, t, m;
        cin >> l >> t >> m;
        int s = l;
        int e = 1e8;
        int ans = -1;

        while (s <= e) {
            int md = s + (e - s) / 2;
            long long cnt = calc(l, md, m);
            if (cnt <= t) {
                ans = md;
                s = md + 1;
            } else {
                e = md - 1;
            }

        }
        cout << ans << endl;
    }

    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int a,b,n;
int l,t,m;
int sum(int r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%d%d%d",&a,&b,&n);
    while(n--)
    {
        scanf("%d%d%d",&l,&t,&m);
        int sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            int ll=l,lr=(t-a)/b+1;
            int mid;
            while(ll<=lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<=t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%d\n",ll-1);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int a,b,n;
int l,t,m;
int sum(int r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%d%d%d",&a,&b,&n);
    while(n--)
    {
        scanf("%d%d%d",&l,&t,&m);
        int sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            int ll=l,lr=(t-a)/b+1;
            int mid;
            while(ll<=lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%d\n",ll-1);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;
typedef long long ll;
ll a,b,n;
ll l,t,m;
int sum(ll r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%d%d%d",&a,&b,&n);
    while(n--)
    {
        scanf("%d%d%d",&l,&t,&m);
        ll sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            ll ll=l,lr=(t-a)/b+1,mid;
            while(ll<=lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<=t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%I64d\n",ll-1);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;
typedef long long ll;
ll a,b,n;
ll l,t,m;
ll sum(ll r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%I64d%I64d%I64d",&a,&b,&n);
    while(n--)
    {
        scanf("%I64d%I64d%I64d",&l,&t,&m);
        ll sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            ll ll=l,lr=(t-a)/b+1,mid;
            while(ll<=lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<=t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%I64d\n",ll-1);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;
typedef long long ll;
ll a,b,n;
ll l,t,m;
int sum(int r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%d%d%d",&a,&b,&n);
    while(n--)
    {
        scanf("%d%d%d",&l,&t,&m);
        ll sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            ll ll=l,lr=(t-a)/b+1,mid;
            while(ll<=lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<=t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%d\n",ll-1);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int a,b,n;
int l,t,m;
int sum(int r)
{
    return (2*a+(l+r-2)*b)*(r-l+1)/2;

}
int main()
{
    scanf("%d%d%d",&a,&b,&n);
    while(n--)
    {
        scanf("%d%d%d",&l,&t,&m);
        int sl=a+(l-1)*b;
        if(sl>t)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            int ll=l,lr=(t-a)/b+1;
            int mid;
            while(ll<lr)
            {
                mid=(ll+lr)/2;
                if(sum(mid)<=t*m) ll=mid+1;
                else lr=mid-1;
            }
          printf("%d\n",ll-1);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long a,b,l,t,m ;
long long func1() ;
long long func2() ;
int main()
{cin.tie(0);
std::ios::sync_with_stdio(false);
long long   i , k , tc;
cin>>a>>b>>tc ;
for(k=0 ;k<tc ; k++){
cin>>l>>t>>m ; if((a+(l-1)*b)>t){  cout<<-1<<endl ; continue ;}
cout<<func2()-1+l<<endl ;
}
return 0 ;
}
long long func1() {long long lo=l , hi=10000000000 , mid ;
while(lo<hi){mid=(lo+hi)/2  ;
if((a+(mid-1)*b)>t){hi=mid-1 ;}
else if((a+(mid-1)*b)<t){lo=mid+1 ;}
else{return mid ;}}
if((a+(hi-1)*b)>t){return hi-1 ;}
if((a+(hi-1)*b)<t&&(a+(hi)*b)<=t){return hi+1 ;}
 return hi ;}

long long func2() {long long lo=1 , hi=func1()-l+1 , mid  ,a1=(a+(l-1)*b);
while(lo<hi){mid=(lo+hi)/2 ;
if((mid*(2*a1+(m-1)*b))/2>t*m){hi=mid-1 ;}
else if((mid*(2*a1+(m-1)*b))/2<t*m){lo=mid+1 ;}
else return mid  ;}
if((hi*(2*a1+(hi-1)*b))/2>t*m){return hi-1 ;}
if((hi*(2*a1+(hi-1)*b))/2<t*m&&((hi+1)*(2*a1+(hi)*b))/2<=t*m&&hi+l<=func1()){return hi+1 ;}
 return hi ;}


#include <bits/stdc++.h>
using namespace std;
long long a , b ;
long long  func (long long  g) ;
int main()
{long long n , l , r , hi , lo , m  , i , k , t, t1;
cin>>a>>b>>n ;
for(k=0 ; k<n ; k++){long long lo1=7874 , hi1=8745 ;
cin>>l>>t>>m ;
if(func(l)>t){cout<<-1<<endl ; continue ;}
t1=t*m ;
lo=l ; hi=t1+1;
while(lo<hi){ m=(lo+hi)/2 ;
lo1=lo ; hi1= hi ;
if( ((m-l+1)/2)*((2*func(l))+(m-l)*b)<=t1&&func(m)<=t){lo=m ;}
else{hi=m-1 ;   }
if(lo==lo1&&hi==hi1){break ;}}
 cout<<lo<<endl ;
   } return 0;
}
long long  func (long long  g) {
return a+(g-1)*b ; }


#include <bits/stdc++.h>
using namespace std;
long long a,b,l,t,m ;
long long func1() ;
long long func2() ;
int main()
{cin.tie(0);
std::ios::sync_with_stdio(false);
long long   i , k , tc;
cin>>a>>b>>tc ;
for(k=0 ;k<tc ; k++){
cin>>l>>t>>m ; if((a+(l-1)*b)>t){  cout<<-1<<endl ; continue ;}
cout<<func2()-1+l<<endl ;
}
return 0 ;
}
long long func1() {long long lo=l , hi=10000000 , mid ;
while(lo<hi){mid=(lo+hi)/2  ;
if((a+(mid-1)*b)>=t){hi=mid ;}
else lo=mid+1 ;}
if((a+(hi-1)*b)>t){return hi-1 ;}
 return hi ;}

long long func2() {long long lo=1 , hi=func1()-l+1 , mid  ,a1=(a+(l-1)*b);
while(lo<hi){mid=(lo+hi)/2 ;
if((mid*(2*a1+(m-1)*b))/2>t*m){hi=mid ;}
else lo=mid+1 ;}
if((hi*(2*a1+(hi-1)*b))/2>t*m){return hi-1 ;}
 return hi ;}


#include <bits/stdc++.h>
using namespace std;
long long a,b,l,t,m ;
long long func1() ;
long long func2() ;
int main()
{cin.tie(0);
std::ios::sync_with_stdio(false);
long long   i , k , tc;
cin>>a>>b>>tc ;
for(k=0 ;k<tc ; k++){
cin>>l>>t>>m ; if((a+(l-1)*b)>t){  cout<<-1<<endl ; continue ;}
cout<<func2()-1+l<<endl ;
}
return 0 ;
}
long long func1() {long long lo=l , hi=10000000 , mid ;
while(lo<hi){mid=(lo+hi)/2  ;
if((a+(mid-1)*b)>t){hi=mid-1 ;}
else if((a+(mid-1)*b)<t){lo=mid+1 ;}
else{return mid ;}}
if((a+(hi-1)*b)>t){return hi-1 ;}
if((a+(hi-1)*b)<t&&(a+(hi)*b)<=t){return hi+1 ;}
 return hi ;}

long long func2() {long long lo=1 , hi=func1()-l+1 , mid  ,a1=(a+(l-1)*b);
while(lo<hi){mid=(lo+hi)/2 ;
if((mid*(2*a1+(m-1)*b))/2>t*m){hi=mid-1 ;}
else if((mid*(2*a1+(m-1)*b))/2<t*m){lo=mid+1 ;}
else return mid  ;}
if((hi*(2*a1+(hi-1)*b))/2>t*m){return hi-1 ;}
if((hi*(2*a1+(hi-1)*b))/2<t*m&&((hi+1)*(2*a1+(hi)*b))/2<=t*m&&hi+l<=func1()){return hi+1 ;}
 return hi ;}


#include <bits/stdc++.h>
using namespace std;
long long a,b,l,t,m ;
long long func1() ;
long long func2() ;
int main()
{cin.tie(0);
std::ios::sync_with_stdio(false);
long long   i , k , tc;
cin>>a>>b>>tc ;
for(k=0 ;k<tc ; k++){
cin>>l>>t>>m ; if((a+(l-1)*b)>t){  cout<<-1<<endl ; continue ;}
cout<<func2()-1+l<<endl ;
}
return 0 ;
}
long long func1() {long long lo=l , hi=10000000000 , mid , lo1 , hi1;
while(lo<hi){mid=(lo+hi)/2 ;lo1=lo ; hi1=hi ;
if((a+(mid-1)*b)>t){hi=mid-1 ;}
else{lo=mid ;}
if(lo1==lo&&hi1==hi){return hi ;}
} return lo ;}

long long func2() {long long lo=1 , hi=func1()-l+1 , mid , lo1 , hi1 ,a1=(a+(l-1)*b);
while(lo<hi){mid=(lo+hi)/2 ;lo1=lo ; hi1=hi ;
if((mid*(2*a1+(m-1)*b))/2>t*m){hi=mid-1 ;}
else{lo=mid ;}
if(lo1==lo&&hi1==hi){return lo ;}
} return lo ;}


#include <bits/stdc++.h>
using namespace std;
long long a,b,l,t,m ;
long long func1() ;
long long func2() ;
int main()
{cin.tie(0);
std::ios::sync_with_stdio(false);
long long   i , k , tc;
cin>>a>>b>>tc ;
for(k=0 ;k<tc ; k++){
cin>>l>>t>>m ; if((a+(l-1)*b)>t){  cout<<-1<<endl ; continue ;}
cout<<func2()-1+l<<endl ;
}
return 0 ;
}
long long func1() {long long lo=l , hi=10000000 , mid ;
while(lo<hi){mid=(lo+hi)/2  ;
if((a+(mid-1)*b)>=t){hi=mid ;}
else lo=mid+1 ;}
if((a+(hi-1)*b)>t){return hi-1 ;}
 return hi ;}

long long func2() {long long lo=1 , hi=func1()-l+1 , mid  ,a1=(a+(l-1)*b);
while(lo<hi){mid=(lo+hi)/2 ;
if((mid*(2*a1+(mid-1)*b))/2>t*m){hi=mid ;}
else lo=mid+1 ;}
if((hi*(2*a1+(hi-1)*b))/2>t*m){return hi-1 ;}
 return hi ;}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <bitset>
#include <vector>

using namespace std;
long long A, B, n;
bool judge(long long s, long long t, long long m, long long time) {
    long long an = A + B * (t - 1), a1 = A + B * (s - 1), n = t - s + 1;
    long long sum = (a1 + an) * n / 2;
//    printf("%I64d %I64d %I64d %I64d \n", t, a1, an, sum);
//    printf("%I64d %I64d %I64d %I64d \n", t, sum, (sum + m - 1) / m, time);
    return max(an, (sum + m - 1) / m) <= time;
}
int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    scanf("%I64d%I64d%I64d", &A, &B, &n);
    while(n--) {
        long long L, t, m;
        scanf("%I64d%I64d%I64d", &L, &t, &m);
        long long low = A + B * (L - 1);
        if(t < low) puts("-1");
        else {
            long long l = L, r = 1e9;
            while(l <= r) {
                long long mid = (l + r) >> 1;
//                printf("%I64d %I64d %I64d %d\n", l, r, mid, judge(L, mid, m, t));
                if(judge(L, mid, m, t)) l = mid + 1;
                else r = mid - 1;
            }
            printf("%I64d\n", r);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <bitset>
#include <vector>

using namespace std;
long long A, B, n;
bool judge(long long s, long long t, long long m, long long time) {
    long long an = A + B * (t - 1), a1 = A + B * (s - 1), n = t - s + 1;
    long long sum = (a1 + an) * n / 2 * B;
//    printf("%I64d %I64d\n", t, sum);
    return max(an, sum / m) <= time;
}
int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    scanf("%I64d%I64d%I64d", &A, &B, &n);
    while(n--) {
        long long L, t, m;
        scanf("%I64d%I64d%I64d", &L, &t, &m);
        long long low = A + B * (L - 1);
        if(t < low) puts("-1");
        else {
            long long l = L, r = 1e9;
            while(l <= r) {
                long long mid = (l + r) >> 1;
//                printf("%I64d %I64d %I64d\n", l, r, mid);
                if(judge(L, mid, m, t)) l = mid + 1;
                else r = mid - 1;
            }
            printf("%I64d\n", r);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <bitset>
#include <vector>

using namespace std;
long long A, B, n;
bool judge(long long s, long long t, long long m, long long time) {
    long long an = A + B * (t - 1), a1 = A + B * (s - 1), n = t - s + 1;
    long long sum = (a1 + an) * n / 2 * B;
//    printf("%I64d %I64d %I64d %I64d \n", t, an, (sum + m - 1) / m, time);
    return max(an, (sum + m - 1) / m) <= time;
}
int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    scanf("%I64d%I64d%I64d", &A, &B, &n);
    while(n--) {
        long long L, t, m;
        scanf("%I64d%I64d%I64d", &L, &t, &m);
        long long low = A + B * (L - 1);
        if(t < low) puts("-1");
        else {
            long long l = L, r = 1e9;
            while(l <= r) {
                long long mid = (l + r) >> 1;
//                printf("%I64d %I64d %I64d %d\n", l, r, mid, judge(L, mid, m, t));
                if(judge(L, mid, m, t)) l = mid + 1;
                else r = mid - 1;
            }
            printf("%I64d\n", r);
        }
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <stack>
#include <bitset>
#include <vector>

using namespace std;
long long A, B, n;
bool judge(long long s, long long t, long long m, long long time) {
    long long an = A + B * (t - 1), a1 = A + B * (s - 1), n = t - s + 1;
    long long sum = (a1 + an) * n / 2;
//    printf("%I64d %I64d %I64d %I64d \n", t, a1, an, sum);
//    printf("%I64d %I64d %I64d %I64d \n", t, sum, (sum + m - 1) / m, time);
    return max(an, (sum + m - 1) / m) <= time;
}
int main() {
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    scanf("%I64d%I64d%I64d", &A, &B, &n);
    while(n--) {
        long long L, t, m;
        scanf("%I64d%I64d%I64d", &L, &t, &m);
        long long low = A + B * (L - 1);
        if(t < low) puts("-1");
        else {
            long long l = L, r = L + (t - A) / B;
            while(l <= r) {
                long long mid = (l + r) >> 1;
//                printf("%I64d %I64d %I64d %d\n", l, r, mid, judge(L, mid, m, t));
                if(judge(L, mid, m, t)) l = mid + 1;
                else r = mid - 1;
            }
            printf("%I64d\n", r);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long A,B,n,l,t,m;
long long calc(long long x)
{
    return A+(x-1)*B;
}
long long calcc(long long r)
{
    return (calc(l)+calc(r))*(r-l+1)/2;
}
signed main()
{
    scanf("%lld%lld%lld",&A,&B,&n);
    for(int i=1;i<=n;i++)
      {
      	scanf("%lld%lld%lld",&l,&t,&m);
      	if(calc(l)>t)
      	  {
      	  	printf("-1\n");
      	  	continue;
          }
        long long ll=l,rr=(t-A)/B+1;
        while(ll<=rr)
          {
          	long long mid=(ll+rr)>>1;
          	if(calcc(mid)<=t*m) ll=mid+1;
          	else rr=mid-1;
          }
        printf("%lld\n",ll-1);
      }
}


#include<cstdio>
#include<iostream>
using namespace std;
long long v0,a;
long long dcsl(long long t)
{
  return v0+a*(t-1);
}
int main( )
{
  long long T,i,j,m,n,st,vt,ci,mid,l,r;
  cin>>v0>>a>>T;
  while (T--)
    {
      scanf("%lld%lld%lld",&st,&vt,&ci);
      if (dcsl(st)>vt)
        {
          cout<<-1<<endl;
          continue;
        }
      long long l=st,r=(vt-v0)/a+1;
      while (l<=r)
        {
          mid=(l+r)/2;
          if ((dcsl(st)+dcsl(mid))*(mid-st+1)/2<=vt*ci)
            l=mid+1;
          else
            r=mid-1;
        }
      cout<<l-1<<endl;
    }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B;
int T;
ll L,t,M;
inline int read()
{
    int tot=0;
    char c=getchar();
    while(c<'0'||c>'9')
        c=getchar();
    while(c>='0'&&c<='9')
    {
        tot=tot*10+c-'0';
        c=getchar();
    }
    return tot;
}
inline ll sum(ll t)
{
    return A+(t-1)*B;
}
inline bool check(ll R)
{
    ll tot=0;
    for(register int i=L;i<=R;i++)
        tot+=sum(i);
    if(tot<=t*M)return 1;
    return 0;
}
int main()
{
    A=read();B=read();T=read();
    //cout<<T<<endl;
    while(T--)
    {
        L=read();
        t=read();
        M=read();
        if(sum(L)>t)
        {
            printf("-1\n");
            continue;
        }
        ll l=L,r=(t-A)/B+1,ans=-1;
        while(l<=r)
        {
            ll mid=l+r>>1;
            if(check(mid))l=mid+1,ans=mid;
            else r=mid-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,n,m,t,l;
int le,rig,mid,ans;
int mx;
int xi(int x)
{
	return a+(x-1)*b;
}
bool check(int x)
{
	if((xi(l)+xi(x))*(x-l+1)/2<=m*t) return 1;
	return 0;
}
int main()
{
	scanf("%d%d%d",&a,&b,&n);
	while(n--)
	{
		scanf("%d%d%d",&l,&t,&m);
		mx=m*t;
		if(xi(l)>t)
		{
			cout<<"-1"<<endl;
			continue;
		}
		le=l;
		rig=(t-a)/b+1;
		while(le<=rig)
		{
			mid=(le+rig)>>1;
			if(check(mid))
			{
				le=mid+1;
				ans=mid;
			}
			else
			{
				rig=mid-1;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
ll a,b,n,l,t,m;
int main(){
	scanf("%lld%lld%lld",&a,&b,&n);
	while(n--){
		scanf("%lld%lld%lld",&l,&t,&m);
		ll r1=(t-a)/b+1;

		ll num=2*a+(l-2)*b;
		ll tmp=1-l;
		ll del=( tmp * b + num ) * ( tmp * b + num ) - 4ll * b * ( num * tmp - 2 * m * t );
		ll r2=(-(num+b*tmp)+sqrt(del))/(2*b);

		ll ans=min(r1,r2);
//		printf("`%lld` `%lld`\n",r1,r2);
		if(ans<l) puts("-1");
		else printf("%lld\n",ans);
	}
	return 0;
}
//


#include <cstdio>
#include <iostream>
using namespace std;
const int N=1e6+1;
typedef long long ll;
ll m,n,a,b,sum,l,r,mid,k,t;
bool flag;
ll f (ll y){
	return a+b*(y-1);
}
bool judge (ll x)
{

    //printf("#%I64d,%I64d\n",sum,x);
    if((f(k)+f(x))*(x-k+1)>>1<=t*m) return true;
    return false;
}

int main()
{
    scanf("%I64d %I64d %I64d",&a,&b,&n);
	for(int i=1;i<=n;++i) {
		scanf("%I64d %I64d %I64d",&k,&t,&m);
		l=k,
		r=(t-1)/b+1;//
	    while(l<=r)
	    {
	        mid=l + ( (r-l)>>1 );
	        if(judge(mid)) l=mid+1;
	        else r=mid-1;
	    }

	    //printf("#%I64d,%I64d\n",t,r+1);
	    if(l-1>k) printf("%I64d\n",l-1);
	    else printf("-1\n");
	}

}


#define ll long long
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
ll a,b,n;
ll l,t,m;

ll cal(ll x)
{
    return a+(x-1)*b;
}

ll getSum(ll r)
{
    return (cal(r)+cal(l))*(r-l+1)/2;
}

int main()
{
    cin>>a>>b>>n;
    while(n--)
	{
		int ans=l-1;
        cin>>l>>t>>m;
        if(cal(l)>t) cout<<"-1"<<endl;
        else
		{
            ll lb=l,rb=(t-a)/b+1,mid;
            while(lb<=rb)
			{
                mid=lb+(rb-lb)/2;
                if(getSum(mid)<=t*m) lb=mid+1,ans=mid;
                else rb=mid-1;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
const int L=2*1e6+10;
using namespace std;

int a,b,n,be,t,m;
int l,r,mid;

long long h(int x){return a+(x-1)*b;}

bool check()
{
	long long sum;
	sum=a*(mid-be+1)+(mid-be+1)*(mid+be-2)/2;
	if(sum<=(long long)t*m) return 1;
	return 0;
}

int main()
{
	int i,j;
	cin>>a>>b>>n;
	while(n--)
	{
	  cin>>be>>t>>m;
	  if(h(be)>t){cout<<-1<<endl; continue;}
	  l=be; r=(t-a)/b+1+1;
	  while(l<r)
	  {
		mid=(l+r)/2;
		if(check()) l=mid+1;
		else r=mid;
	  }
	  cout<<l-1<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int main()
{
    long long a,b,n,l,m,t;
    int i,j;
    a=read(),b=read(),n=read();
    for(i=1;i<=n;i++)
    {
        l=read(),t=read(),m=read();
        long long left=l,mid,right=(t-a)/b+1;
        if(right<l) cout<<-1<<endl;
        else if((l*b+a-b+right*b+a-b)*(right-l+1)/2<=t*m) cout<<right<<endl;
        else
        {
          while(left<=right)
        {
            mid=(left+right)/2;
            if((l*b+a-b+mid*b+a-b)*(mid-l+1)/2<=t*m) left=mid+1;
            else right=mid-1;
        }
        cout<<left-1<<endl;
        }
    }
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int v0,a;
int dcsl(int t)
{
  return v0+a*(t-1);
}
int main( )
{
  int T,i,j,m,n,st,vt,ci,mid,l,r;
  cin>>v0>>a>>T;
  while (T--)
    {
      scanf("%d%d%d",&st,&vt,&ci);
      if (dcsl(st)>vt)
        {
          cout<<-1<<endl;
          continue;
        }
      int l=st,r=(vt-v0)/a+1;
      while (l<=r)
        {
          mid=(l+r)/2;
          if ((dcsl(st)+dcsl(mid))*(mid-st+1)/2<=vt*ci)
            l=mid+1;
          else
            r=mid-1;
        }
      cout<<l-1<<endl;
    }
  return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int fuck_qhw=0x3f3f3f3f;
int n,m;
int a,b;
int ans;
int u,t,v;
int he(int x)
{
	return a+(x-1)*b;
}
int check(int x)
{
	return (he(u)+he(x))*(x-u+1)/2;
}
int main()
{
	while(scanf("%d %d %d",&a,&b,&n)!=EOF)
	{
		while(n--)
		{
			scanf("%d%d%d",&u,&t,&v);
			if(he(u)>t)
			{
				printf("-1\n");
				continue;
			}
			else
			{
				int l=u;
				int r=(t-a)/b+1;
				int mid;
				while(l<=r)
				{
					mid=l+((r-l)>>1);
					if(check(mid)<=t*v)
					{
						l=mid+1;
						ans=mid;
					}
					else
					r=mid-1;
				}
				printf("%d\n",ans);
			}

		}

	}
	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		// cout << "n1: " << n1 << " n2: " << n2 << endl;

		ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 10;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			// cout << "sum for " << mid << " is " << sum << endl;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			// cout << "mint: " << mint << endl;

			if (mint <= t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		// cout << "n1: " << n1 << " n2: " << n2 << endl;

		ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 1;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			// cout << "sum for " << mid << " is " << sum << endl;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			// cout << "mint: " << mint << endl;

			if (mint <= t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		if (A + B * l > t) {
			cout << "-1" << endl;
			continue;
		}

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		double n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		double n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		ll lo = 1, hi = (ll) max(n1, n2) + 1;
		ll mi;
		while (lo < hi) {
			mi = (lo + hi) / 2;
			ll r = l + mi - 1;
			if (A + B * r <= t) lo = mi + 1;
			else hi = mi;
		}

		cout << (l + lo - 1) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 1;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long double

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		// cout << "n1: " << n1 << " n2: " << n2 << endl;

		ll lo = max(floor(min(n1, n2)), (ll) 0);
		ll hi = ceil(max(max(n1, n2), (ll) 0)) + 1;
		ll mid;
		while (lo < hi) {
			mid = floor((lo + hi) / 2);

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			// cout << "sum for " << mid << " is " << sum << endl;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				mint = ceil(sum / t);
			}

			// cout << "mint: " << mint << endl;

			if (mint <= t && sum <= m * t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				mint = ceil(sum / t);
			}

			if (mint <= t && sum <= m * t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		if (A + B * l > t) {
			cout << "-1" << endl;
			continue;
		}

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		double lim = max((1 - 2 * a1 + sqrt(delta)) / (2 * B), (1 - 2 * a1 - sqrt(delta)) / (2 * B));

		ll lo = 1, hi = (ll) lim + 5;
		ll mi;
		while (lo < hi) {
			mi = (lo + hi) / 2;
			ll r = l + mi - 1;
			if (A + B * r <= t && mi <= lim) lo = mi + 1;
			else hi = mi;
		}

		cout << (l + lo - 1) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 2;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		if (A + B * l > t) {
			cout << "-1" << endl;
			continue;
		}

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		double lim = max((1 - 2 * a1 + sqrt(delta)) / (2 * B), (1 - 2 * a1 - sqrt(delta)) / (2 * B));

		ll lo = 1, hi = (ll) lim + 5;
		ll mi;
		while (lo < hi) {
			mi = (lo + hi) / 2;
			ll r = l + mi - 1;
			ll s = ((A + B * l) + (A + B * r)) * mi / 2;
			if (A + B * r <= t && s <= sum) lo = mi + 1;
			else hi = mi;
		}

		cout << (l + lo - 1) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		if (A + B * l > t) {
			printf("-1\n");
			continue;
		}

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		double n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		double n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		ll lo = 1, hi = (ll) max(n1, n2) + 1;
		ll mi;
		while (lo < hi) {
			mi = (lo + hi) / 2;
			ll r = l + mi - 1;
			if (A + B * r <= t) lo = mi + 1;
			else hi = mi;
		}

		cout << (l + lo - 1) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		ll from = max(min(n1, n2), (ll) 1);
		ll to = max(max(n1, n2), (ll) 0) + 10;

		ll ret = -1;
		for (ll use = to; use >= from; use--) {
			ll mid = use;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) {
				ret = l + mid;
				break;
			}
		}

		cout << ret << endl;

		// cout << "n1: " << n1 << " n2: " << n2 << endl;

		/*ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 10;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			// cout << "sum for " << mid << " is " << sum << endl;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			// cout << "mint: " << mint << endl;

			if (mint <= t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;*/
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	ll A, B, n;
	cin >> A >> B >> n;

	while (n--) {
		ll l, t, m;
		cin >> l >> t >> m;
		l--;

		ll sum = m * t;
		ll a1 = A + B * l;
		double delta = pow(2 * a1 - 1, 2) + 8 * B * sum;
		ll n1 = (1 - 2 * a1 + sqrt(delta)) / (2 * B);
		ll n2 = (1 - 2 * a1 - sqrt(delta)) / (2 * B);

		// cout << "n1: " << n1 << " n2: " << n2 << endl;

		ll lo = max(min(n1, n2), (ll) 0);
		ll hi = max(max(n1, n2), (ll) 0) + 10;
		ll mid;
		while (lo < hi) {
			mid = (lo + hi) / 2;

			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			// cout << "sum for " << mid << " is " << sum << endl;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			// cout << "mint: " << mint << endl;

			if (mint <= t && sum <= m * t) lo = mid + 1;
			else hi = mid;
		}

		lo--;
		bool found = false;
		if (lo > 0) {
			mid = lo;
			ll r = l + mid - 1;
			sum = (A + B * l + A + B * r) * mid / 2;

			ll mint = 0;
			if (m >= (r - l + 1)) mint = A + B * r;
			else {
				if (sum % m == 0) mint = sum / m;
				else mint = sum / m + 1;
			}

			if (mint <= t && sum <= m * t) found = true;
		}

		if (found) cout << (l + mid) << endl;
		else cout << "-1" << endl;
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using	namespace	std;

const	long long	SIZE = 1000005;
long	long	S[SIZE];
long	long	ANS[SIZE];
long long	L,t;

long long	bsearch(long long box,long long r);
long long	bsearch(long long r);
int	main(void)
{
	long long	a,b,n,m,r;

	scanf("%lld%lld%lld",&a,&b,&n);
	S[0] = a - b;
	ANS[0] = 0;
	for(long long i = 1;i < SIZE;i ++)
	{
		S[i] = S[i - 1] + b;
		ANS[i] = S[i] + ANS[i - 1];
	}

	while(n --)
	{
		scanf("%lld%lld%lld",&L,&t,&m);
		if(S[L] > t)
		{
			printf("-1\n");
			continue;
		}

		long	long	box = m * t;
		r = bsearch(box,(t - a + b) / b + 2);
		if(ANS[r + 1] - ANS[L - 1] <= box)
			r += 1;
		else	if(ANS[r] - ANS[L - 1] > box)
			r -= 1;
		r = bsearch(r);
		if(S[r + 1] <= t && ANS[r + 1] - ANS[L - 1] <= box)
			r = r + 1;
		else	if(S[r] > t)
			r = r - 1;
		printf("%lld\n",r);
	}
	return	0;
}

long long	bsearch(long long box,long long r)
{
	long long	low = L;
	long long	high = r;

	while(low < high)
	{
		long long	mid = (low + high) / 2;
		long	long	temp = ANS[mid] - ANS[L - 1];

		if(box > temp)
		{
			low = mid + 1;
			continue;

		}
		else	if(box < temp)
		{
			high = mid - 1;
			continue;
		}
		else	if(box == temp && S[mid] <= t)
			return	mid;
	}

	return	low;
}

long long	bsearch(long long r)
{
	long long	low = L;
	long long	high = r;

	while(low < high)
	{
		long long	mid = (low + high) / 2;

		if(S[mid] < t)
		{
			low = mid + 1;
			continue;
		}
		else	if(S[mid] > t)
		{
			high = mid - 1;
			continue;
		}
		else	if(S[mid] == t)
			return	mid;
	}

	return	low;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using	namespace	std;

const	int	SIZE = 1000005;
long	long	S[SIZE];
long	long	ANS[SIZE];
int	L,t;

int	bsearch(long long box,int r);
int	bsearch(int r);
int	main(void)
{
	int	a,b,n,m,r;

	scanf("%d%d%d",&a,&b,&n);
	S[0] = a - b;
	ANS[0] = 0;
	for(int i = 1;i < SIZE;i ++)
	{
		S[i] = S[i - 1] + b;
		ANS[i] = S[i] + ANS[i - 1];
	}

	while(n --)
	{
		scanf("%d%d%d",&L,&t,&m);
		if(S[L] > t)
		{
			printf("-1\n");
			continue;
		}

		long	long	box = m * t;
		r = bsearch(box,(t - a + b) / b + 2);
		if(ANS[r + 1] - ANS[L - 1] <= box)
			r += 1;
		else	if(ANS[r] - ANS[L - 1] > box)
			r -= 1;
		r = bsearch(r);
		if(S[r + 1] <= t && ANS[r + 1] - ANS[L - 1] <= box)
			r = r + 1;
		else	if(S[r] > t)
			r = r - 1;
		else	if(ANS[r] - ANS[L - 1] > box)
			r = r - 1;

		printf("%d\n",r);
	}
	return	0;
}

int	bsearch(long long box,int r)
{
	int	low = L;
	int	high = r;

	while(low < high)
	{
		int	mid = (low + high) / 2;
		long	long	temp = ANS[mid] - ANS[L - 1];

		if(box > temp)
		{
			low = mid + 1;
			continue;

		}
		else	if(box < temp)
		{
			high = mid - 1;
			continue;
		}
		else	if(box == temp && S[mid] <= t)
			return	mid;
	}

	return	low;
}

int	bsearch(int r)
{
	int	low = L;
	int	high = SIZE - 10;

	while(low < high)
	{
		int	mid = (low + high) / 2;

		if(S[mid] < t)
		{
			low = mid + 1;
			continue;
		}
		else	if(S[mid] > t)
		{
			high = mid - 1;
			continue;
		}
		else	if(S[mid] == t)
			return	mid;
	}

	return	low;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using	namespace	std;

const	int	SIZE = 1000005;
long	long	S[SIZE];
long	long	ANS[SIZE];
int	L,t;

int	bsearch(long long box,int r);
int	bsearch(int r);
int	main(void)
{
	int	a,b,n,m,r;

	scanf("%d%d%d",&a,&b,&n);
	S[0] = a - b;
	ANS[0] = 0;
	for(int i = 1;i < SIZE;i ++)
	{
		S[i] = S[i - 1] + b;
		ANS[i] = S[i] + ANS[i - 1];
	}

	while(n --)
	{
		scanf("%d%d%d",&L,&t,&m);
		if(S[L] > t)
		{
			printf("-1\n");
			continue;
		}

		long	long	box = m * t;
		r = bsearch(box,(t - a + b) / b + 2);
		if(ANS[r + 1] - ANS[L - 1] <= box)
			r += 1;
		else	if(ANS[r] - ANS[L - 1] > box)
			r -= 1;
		r = bsearch(r);
		if(S[r + 1] <= t && ANS[r + 1] - ANS[L - 1] <= box)
			r = r + 1;
		else	if(S[r] > t)
			r = r - 1;
		printf("%d\n",r);
	}
	return	0;
}

int	bsearch(long long box,int r)
{
	int	low = L;
	int	high = r;

	while(low < high)
	{
		int	mid = (low + high) / 2;
		long	long	temp = ANS[mid] - ANS[L - 1];

		if(box > temp)
		{
			low = mid + 1;
			continue;

		}
		else	if(box < temp)
		{
			high = mid - 1;
			continue;
		}
		else	if(box == temp && S[mid] <= t)
			return	mid;
	}

	return	low;
}

int	bsearch(int r)
{
	int	low = L;
	int	high = r;

	while(low < high)
	{
		int	mid = (low + high) / 2;

		if(S[mid] < t)
		{
			low = mid + 1;
			continue;
		}
		else	if(S[mid] > t)
		{
			high = mid - 1;
			continue;
		}
		else	if(S[mid] == t)
			return	mid;
	}

	return	low;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <ctime>
using	namespace	std;

int	bsearch(int,int,int);

int	A,B;
int	main(void)
{
	int	l,t,m,r;
	int	n;

	scanf("%d%d%d",&A,&B,&n);
	while(n --)
	{
		scanf("%d%d%d",&l,&t,&m);
		if(t < A + (l - 1) * B)
		{
			puts("-1");
			continue;
		}
		r = bsearch(l,t,m);
		printf("%d\n",r);
	}

	return	0;
}

int	bsearch(int l,int t,int m)
{
	int	low = l;
	int	high = (t - A) / B + 1;

	while(low <= high)
	{
		long	long	mid = (low + high) / 2;

		long	long	box = (mid - l + 1) * (2 * A - 2 * B + l * B + mid * B) / 2;
		if(box <= m * t)
			low = mid + 1;
		else
			high = mid - 1;
	}

	return	low - 1;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <ctime>
using	namespace	std;

long long	bsearch(long long,long long,long long);

long long	A,B;
int		main(void)
{
	long long	l,t,m,r;
	long long	n;

	scanf("%lld%lld%lld",&A,&B,&n);
	while(n --)
	{
		scanf("%lld%lld%lld",&l,&t,&m);
		if(t < A + (l - 1) * B)
		{
			puts("-1");
			continue;
		}
		r = bsearch(l,t,m);
		printf("%lld\n",r);
	}

	return	0;
}

long long	bsearch(long long l,long long t,long long m)
{
	long long	low = l;
	long long	high = (t - A) / B + 1;

	while(low <= high)
	{
		long	long	mid = (low + high) / 2;
		long	long	box = (A + (l - 1) * B + A + (mid - 1) * B) * (mid - l + 1) / 2;

		if(box <= m * t)
			low = mid + 1;
		else
			high = mid - 1;
	}

	return	low - 1;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		int z;

		int t1 = A + (l-1)*B;
		for(z = 1;;z++){
			int som = z*t1+((z*(z-1))/2)*B; // som hoogtes hoop ik
			if(som > m*t)
				break;
			if(t1+(z-1)*B > t) // hoogte hoogste stapel
				break;
		}
		if(z == 1)
			cout << -1<< endl;
		else
			cout << z+l-2 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		int z;

		int t1 = A + (l-1)*B;
		int left = 1, right = 1000000;
		int sol;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			sol = z-1;
			if((z*t1+((z*(z-1))/2)*B > m*t || t1+(z-1)*B > t) && sol*t1+((sol*(sol-1))/2)*B <= m*t && t1+(sol-1)*B <= t)
				break;
			else if(z*t1+((z*(z-1))/2)*B <= m*t && t1+(z-1)*B <= t) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(z == 1 || sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(int A, int B, int l, int t, int m, int z){ //z is aantal stapels
	int t1 = A + (l-1)*B;
	return (z*t1+((z*(z-1))/2)*B <= min(m, z)*t && t1+(z-1)*B <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol = 0;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(!possible(A,B,l,t,m,z) && possible(A,B,l,t,m,z-1)){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll t1 = A + (l-1)*B;
		ll left = 1, right = 1000000;
		ll sol;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			sol = z-1;
			if((z*t1+((z*(z-1))/2)*B > min(m, z)*t || t1+(z-1)*B > t) && sol*t1+((sol*(sol-1))/2)*B <= min(m, sol)*t && t1+(sol-1)*B <= t)
				break;
			else if(z*t1+((z*(z-1))/2)*B <= min(m, z)*t && t1+(z-1)*B <= t) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(ll A, ll B, ll l, ll t, ll m, ll z){ //z is aantal stapels
	ll t1 = A + (l-1)*B;
	ll tn =  t1+(z-1)*B;
	return (z*(t1+tn)/2 <= min(m, z)*t && tn <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol = 0;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(z == 0 || !possible(A,B,l,t,m,z) && possible(A,B,l,t,m,z-1)){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(int A, int B, int l, int t, int m, int z){ //z is aantal stapels
	int t1 = A + (l-1)*B;
	int tn =  t1+(z-1)*B;
	return (z*(t1+tn)/2 <= min(m, z)*t && tn <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol = 0;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(!possible(A,B,l,t,m,z) && possible(A,B,l,t,m,z-1)){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(ll A, ll B, ll l, ll t, ll m, ll z){ //z is aantal stapels
	int t1 = A + (l-1)*B;
	int tn =  t1+(z-1)*B;
	return (z*(t1+tn)/2 <= min(m, z)*t && tn <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol = 0;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(z == 0 || !possible(A,B,l,t,m,z) && possible(A,B,l,t,m,z-1)){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll t1 = A + (l-1)*B;
		ll left = 1, right = 1500000;
		ll sol;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			sol = z-1;
			if((z*t1+((z*(z-1))/2)*B > min(m, z)*t || t1+(z-1)*B > t) && sol*t1+((sol*(sol-1))/2)*B <= min(m, sol)*t && t1+(sol-1)*B <= t)
				break;
			else if(z*t1+((z*(z-1))/2)*B <= min(m, z)*t && t1+(z-1)*B <= t) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(int A, int B, int l, int t, int m, int z){ //z is aantal stapels
	int t1 = A + (l-1)*B;
	int tn =  t1+(z-1)*B;
	return (z*(t1+tn)/2 <= min(m, z)*t && tn <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol = 0;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(z == 0 || !possible(A,B,l,t,m,z) && possible(A,B,l,t,m,z-1)){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

ll A,B, l, t, m;
ll t1;
inline bool possible(ll z){ //z is aantal stapels
	ll tn =  t1+(z-1)*B;
	return (z*(t1+tn)/2 <= min(m, z)*t && tn <= t);
}

int main(){
	int n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		cin >> l >> t >> m;
		ll z;

		t1 = A + (l-1)*B;
		ll left = 1, right = 1500000;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(z == 0 || !possible(z) && possible(z-1)){
				break;
			}
			else if(possible(z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(z <= 1)
			cout << -1<< endl;
		else
			cout << z+l-2 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;

bool possible(int A, int B, int l, int t, int m, int z){ //z is aantal stapels
	int t1 = A + (l-1)*B;
	return (z*t1+((z*(z-1))/2)*B <= min(m, z)*t && t1+(z-1)*B <= t);
}

int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		ll z;

		ll left = 1, right = 1500000;
		ll sol;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			if(!possible(A,B,l,t,m,z) && (possible(A,B,l,t,m,z-1))){
				sol = z-1;
				break;
			}
			else if(possible(A,B,l,t,m,z)) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		int z;

		int t1 = A + (l-1)*B;
		cout << t1 << endl;
		for(z = 1;;z++){
			int som = z*t1+((z*(z-1))/2)*B; // som hoogtes hoop ik
			if(som > m*t)
				break;
			if(t1+(z-1)*B > t) // hoogte hoogste stapel
				break;
		}
		if(z == 1)
			cout << -1<< endl;
		else
			cout << z+l-2 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long

using namespace std;
int main(){
	ll A,B,n;
	cin >> A >> B >> n;
	for(int i = 0; i < n; i++){
		ll l, t, m;
		cin >> l >> t >> m;
		int z;

		int t1 = A + (l-1)*B;
		int left = 1, right = 1000000;
		int sol;
		while(left <= right){
			//cout << left << ", " << right << endl;
			z = (left + right)/2;
			sol = z-1;
			if((z*t1+((z*(z-1))/2)*B > m*t || t1+(z-1)*B > t) && sol*t1+((sol*(sol-1))/2)*B <= m*t && t1+(sol-1)*B <= t)
				break;
			else if(z*t1+((z*(z-1))/2)*B <= m*t && t1+(z-1)*B <= t) // som hoogtes && hoogte hoogste stapel
				left = z+1;
			else
				right = z-1;
		}

		if(sol == 0)
			cout << -1<< endl;
		else
			cout << sol+l-1 << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a,b,n,l,t,m;
long long cum[2000001],h[2000001];

long long high(long long i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=2000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(long long mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%lld%lld%lld",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		long long lo=1,hi=2e6,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%lld\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a,b,n,l,t,m;
long long cum[2000001],h[2000001];

long long high(int i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=2000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(int mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%d%d%d",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%d%d%d",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		int lo=1,hi=2e6,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%d\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(long long i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(long long mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%lld%lld%lld",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		long long lo=1,hi=t+l+100,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%lld\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a,b,n,l,t,m;
long long cum[2000001+100],h[2000001+100];

long long high(long long i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=2000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(long long mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%lld%lld%lld",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		long long lo=1,hi=t+l+100,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%lld\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(int i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(int mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%d%d%d",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%d%d%d",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		int lo=1,hi=1e6,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%d\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(long long i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(long long mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%lld%lld%lld",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		long long lo=1,hi=t+l,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%lld\n",lo);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long a,b,n,l,t,m;
long long cum[2000001],h[2000001];

long long high(long long i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=2000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(long long mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%lld%lld%lld",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%lld%lld%lld",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		long long lo=1,hi=2e6,mid;
    		while(lo<hi)
    		{
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%lld\n",hi);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(int i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(int mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%d%d%d",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%d%d%d",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		int lo=1,hi=2e6,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%d\n",hi);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(int i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(int mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%d%d%d",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%d%d%d",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		int lo=1,hi=t+l,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%d\n",hi);
    	}
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a,b,n,l,t,m;
long long cum[1000001],h[1000001];

long long high(int i)
{
	return (a+((i-1)*b));
}

void gen()
{
	cum[1]=high(1);
	h[1]=high(1);
	for(int i=2;i<=1000000;i++)
	{
		cum[i]+=(high(i)+cum[i-1]);
		h[i]=high(i);
	}
}

bool valid(int mid)
{
	long long sum=cum[mid]-cum[l-1];
	long long maxx=h[mid];
	return (sum<=m*t)&&(maxx<=t);
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(scanf("%d%d%d",&a,&b,&n)!=EOF)
    {
    	gen();
    	while(n--)
    	{
    		scanf("%d%d%d",&l,&t,&m);
    		if(high(l)>t)
    		{
    			printf("-1\n");
    			continue;
    		}
    		int lo=1,hi=2e6,mid;
    		while(lo<hi)
    		{
    			//cout<<lo<<" "<<hi<<endl;
    			mid=(lo+hi)/2;
    			if(valid(mid))
    				lo=mid;
    			else
    				hi=mid-1;
    			if(lo+1==hi)
    			{
    				if(valid(lo+1))
    					lo=hi;
    				else
    					hi=lo;
    			}
    		}
    		printf("%d\n",lo);
    	}
    }
    return 0;
}


#include <cctype>
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <string>
#include <iomanip>
#include <iterator>

#define forn(i, n) for (i64 i = 0; i < n; ++i)
#define revn(i, n) for (i64 i = n-1; i>=0; --i)
#define cyc(i, s, n) for (i64 i = s; i <= n; ++i)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define eps 1e-7
#define inf 1e15

using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef long double ld;
typedef vector < i64 > vi64;
typedef vector < u64 > vu64;
typedef pair < i64, i64 > pi64;
typedef vector < vi64 > graph;
typedef int huint;
#define huint int

//fstream in("input.txt"), out("output.txt", 2);

i64 n, a, b;

i64 ap(i64 p)
{
    return p*(p+1)/2;
}

i64 seg(i64 l, i64 r)
{
    i64 p = r-l+1;
    return a*p+b*(ap(r-1)-ap(l-2));
}

i64 val(i64 i)
{
    return a+(i-1)*b;
}

i64 st(i64 mx)
{
    return (mx-a)/b+1;
}

i64 bs(i64 l, i64 t, i64 m)
{
    i64 max = m*t;
    if (val(l)>t)
        return -1;
    i64 R = 1e7, L=l;
    while (R>L) {
        i64 mid = (R+L)/2;
        if (seg(l, mid)<=max)
            L=mid+1;
        else R=mid;
    }
    return L-1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> a >> b >> n;
    i64 t,l,m;
    forn(i, n)
    {
        cin >> l >> t >> m;
        cout << endl << min(st(t),bs(l, t, m));
    }

}


#include <cctype>
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <string>
#include <iomanip>
#include <iterator>

#define forn(i, n) for (i64 i = 0; i < n; ++i)
#define revn(i, n) for (i64 i = n-1; i>=0; --i)
#define cyc(i, s, n) for (i64 i = s; i <= n; ++i)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define eps 1e-7
#define inf 1e15

using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef long double ld;
typedef vector < i64 > vi64;
typedef vector < u64 > vu64;
typedef pair < i64, i64 > pi64;
typedef vector < vi64 > graph;
typedef int huint;
#define huint int

//fstream in("input.txt"), out("output.txt", 2);

i64 n, a, b;

i64 ap(i64 p)
{
    return p*(p+1)/2;
}

i64 seg(i64 l, i64 r)
{
    i64 p = r-l+1;
    return a*p+b*(ap(r-1)-ap(l-2));
}

i64 val(i64 i)
{
    return a+(i-1)*b;
}

i64 st(i64 mx)
{
    return (mx-a)/b+1;
}

i64 bs(i64 l, i64 t, i64 m)
{
    i64 max = m*t;
    if (val(l)>t)
        return -1;
    i64 R = 2e6, L=l;
    while (R>L) {
        i64 mid = (R+L)/2;
        if (seg(l, mid)<=max)
            L=mid+1;
        else R=mid;
    }
    return L-1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> a >> b >> n;
    i64 t,l,m;
    forn(i, n)
    {
        cin >> l >> t >> m;
        cout << endl << min(st(t),bs(l, t, m));
    }

}


#include <cctype>
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <string>
#include <iomanip>
#include <iterator>

#define forn(i, n) for (i64 i = 0; i < n; ++i)
#define revn(i, n) for (i64 i = n-1; i>=0; --i)
#define cyc(i, s, n) for (i64 i = s; i <= n; ++i)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define eps 1e-7
#define inf 1e15

using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef long double ld;
typedef vector < i64 > vi64;
typedef vector < u64 > vu64;
typedef pair < i64, i64 > pi64;
typedef vector < vi64 > graph;
typedef int huint;
#define huint int

//fstream in("input.txt"), out("output.txt", 2);

int main()
{
    ios_base::sync_with_stdio(false);
    i64 a,b,n,t,l,m;
    cin >> a >> b >> n;
    forn(i, n)
    {
        cin >> l >> t >> m;
        cout << endl << ((a+b*(l-1)>t)?-1:min((t-a)/b+1, (i64)(l+(sqrt((2*a-3*b+2*l*b)*(2*a-3*b+2*l*b)+(8*b*m*t))-(2*a-3*b+2*l*b))/2/b-1)));
    }

}


#include <cctype>
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <set>
#include <string>
#include <iomanip>
#include <iterator>

#define forn(i, n) for (i64 i = 0; i < n; ++i)
#define revn(i, n) for (i64 i = n-1; i>=0; --i)
#define cyc(i, s, n) for (i64 i = s; i <= n; ++i)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define eps 1e-7
#define inf 1e15

using namespace std;
typedef unsigned long long u64;
typedef long long i64;
typedef long double ld;
typedef vector < i64 > vi64;
typedef vector < u64 > vu64;
typedef pair < i64, i64 > pi64;
typedef vector < vi64 > graph;
typedef int huint;
#define huint int

//fstream in("input.txt"), out("output.txt", 2);

i64 n, a, b;

i64 hehehe(i64 l, i64 t, i64 m)
{
    if (a+b*(l-1)>t)
        return -1;
    else {
        i64 cnst = 2*a-3*b+2*l*b;
        i64 d = (sqrt(cnst*cnst+(8*b*m*t))-cnst)/2/b;
        return min((t-a)/b+1, l+d-1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> a >> b >> n;
    i64 t,l,m;
    forn(i, n)
    {
        cin >> l >> t >> m;
        cout << endl << hehehe(l,t,m);
    }

}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val MAX = 1_000_000
    val N = ni()
    val C = IntArray(MAX + 10)
    for (i in 0 until N) {
      val a = ni()
      C[a]++
    }

    fun findSqure(): Long {
      for (i in MAX downTo 2) {
        if (C[i] + C[i + 1] >= 4) {
          return i.toLong() + i
        }
      }
      return 0
    }

    fun find(): Long {
      for (i in MAX downTo 2) {
        if (C[i] + C[i + 1] >= 2) {
          var c = 2
          for (j in 1 downTo 0) {
            val v = min(c, C[i + j])
            c -= v
            C[i + j] -= v
          }
          return i.toLong()
        }
      }
      return 0
    }

    var ans = findSqure()
    ans = max(ans, find() * find())
    out.println(ans)

  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n, offset) { ni() }
  }

  private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i + offset)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun <A, B> pair(a: A, b: B) = RPair(a, b)
data class RPair<A, B>(val _1: A, val _2: B)

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}