import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
    static int N = (int)(5e5 + 10);
    static long[] k = new long[N], a = new long[N], b = new long[N];
    static int n,l,r,fl,fr,fm;

    static long f(int x, int idx) {
        return Math.abs(k[idx]*x+a[idx])+b[idx];
    }

    static long F(int x) {
        long sum = 0;
        for(int i=1;i<=n;i++) {
            sum+=f(x,i);
        }
        return sum;
    }

    static void solve() {
        n = in.nextInt();
        l = in.nextInt();
        r = in.nextInt();
        for(int i=1;i<=n;i++) {
            k[i] = in.nextLong();
            a[i] = in.nextLong();
            b[i] = in.nextLong();
        }
        while(r-l>2) {
            fm =(r-l)/3;
            fl=l+fm;
            fr=fl+fm;
            if(F(fl)<F(fr)) r=fr;
            else l=fl;
        }
        long ans=(long)9e18;
        for(int i=l;i<=r;i++){
            ans = Math.min(ans,F(i));
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        int T = in.nextInt();
        while(T-->0) {
            solve();
        }
        out.flush();
    }

    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    static class FastReader {
        static BufferedReader br;
        static StringTokenizer st;

        FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            String str = "";
            while (st == null || !st.hasMoreElements()) {
                try {
                    str = br.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                st = new StringTokenizer(str);
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}