// Arup Guha
// 4/27/202
// Solution to 2020 FHSPS Problem: Christmas Ornaments

// After I wrote my original solution, I realized that I could just get a
// DP to run in time with a state of (person I am on, ornaments left to buy)
// Run time is O(n*target*target). In this problem n <= 20, target <= 1000,
// so it's okay.

import java.util.*;

public class ornaments_alt {
	
	final public static long MOD = 1000000007L;
	
	public static int n;
	public static int target;
	public static int[] low;
	public static int[] high;
	public static long[][] memo;
	
	public static void main(String[] args) {
	
		// Now process input.
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process all cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Store # of council people # target # of ornaments.
			n = stdin.nextInt();
			target = stdin.nextInt();
			
			// Store ranges here.
			low = new int[n];
			high = new int[n];
			for (int i=0; i<n; i++) {
				low[i] = stdin.nextInt();
				high[i] = stdin.nextInt();
			}
			
			// memo[i][j] will store # of ways to buy j ornaments using council members
			// with index i or higher.
			memo = new long[n+1][target+1];
			for (int i=0; i<=n; i++) Arrays.fill(memo[i], -1);
			
			// Ta da!
			System.out.println(go(0,target));
		}
	}
	
	// Returns the # of ways for council members k..n-1 to buy exactly numOrnaments.
	public static long go(int k, int numOrnaments) {
		
		// Easy case.
		if (numOrnaments < 0) return 0;
		
		// No more people, has to be 0 to count.
		if (k == n) return numOrnaments == 0 ? 1 : 0;
		
		// We did this case already.
		if (memo[k][numOrnaments] != -1) return memo[k][numOrnaments];
		
		// Just add up each possibility, looping through trying each # of ornaments.
		long res = 0;
		for (int i=low[k]; i<=high[k]; i++)
			res = (res + go(k+1, numOrnaments-i))%MOD;
		
		// Ta da!
		return memo[k][numOrnaments] = res;
	}
}