Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

<image>

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

Input

The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

Output

For each query, print its answer in a single line.

Examples

Input

2 1 4
1 5 3
3 3 10
7 10 2
6 4 8


Output

4
-1
8
-1


Input

1 5 2
1 5 10
2 7 4


Output

1
2
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static boolean file = false;
    static final int maxn = (int)6e6+111;
    static int inf = (int)1e9;
    static int n,A,B;
    static long a[] = new long [maxn];
    
    private static void solve() throws Exception {
        A = in.nextInt();
        B = in.nextInt();
        n = in.nextInt();
        precalc();
        for (int i=1; i<=n; i++) {
            int l = in.nextInt();
            int t = in.nextInt();
            int m = in.nextInt();
            
            long ans = binarySearch(l,t,m);
            out.println(ans);
        }

    }   
    
    private static void precalc() {
        for (int i=1; i<=maxn-1; i++) {
            a[i] = a[i-1] + (long)((long)A+(i-1)*(long)B);
        }
    }

    private static int binarySearch(int left, int t, int m) {
        int l = left;
        int r = 6000000;
        int res = -1;
        while (l<=r) {
            int mid = (l+r)/2;
            if (check(left,mid,m,t)) {
                l = mid + 1;
                res = mid;
            } else {
                r = mid - 1;
            }
        }
        
        return res;
    }

    // referred to aidos.nurmash's solution
    private static boolean check(int left,int mid, int m, int t) {
        long sum = a[mid]-a[left-1];
        if(mid-left > m-1){
            if((sum > (long)t*m) || a[mid] - a[mid-1] > t) return false;
            return true;

        }
        return a[mid] - a[mid-1] <= t;
    }

    public static void main (String [] args) throws Exception {
        
        if (file) {
            in = new FastReader(new BufferedReader(new FileReader("input.txt")));
            out = new PrintWriter ("output.txt");
        }
        
        solve();
        out.close();
    }

}

class Pair implements Comparable<Pair> {
    long x,y;
    
    public Pair(long a, long b) {
        this.x = a;
        this.y = b;
    }
    @Override
    public boolean equals(Object obj) {
        Pair p = (Pair)obj;
        if (p.x == x && p.y==y) return true;
        return false;
    }
    
    @Override
    public int compareTo(Pair p) {
        if (this.y>p.y) return 1;
        else if (this.y==p.y) {
            return 0;
        }
        else return -1;
    }
    
    
    
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }
    
    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}