// Arup Guha
// 4/27/202
// Solution to 2020 FHSPS Problem: Christmas Ornaments
// This solution uses the inclusion-exclusion principle on all subsets of council members.

import java.util.*;

public class ornaments {

	final public static int MAXROWS = 1100;
	
	final public static long MOD = 1000000007L;
	
	public static void main(String[] args) {
		
		// Seed Pascal's Triangle...we just need a few more rows than 1000.
		long[][] combo = new long[MAXROWS][MAXROWS];
		for (int i=0; i<MAXROWS; i++) {
			combo[i][0] = 1;
			combo[i][i] = 1;
		}
		
		// Add the two values on the previous row...
		for (int i=2; i<MAXROWS; i++)
			for (int j=1; j<i; j++)
				combo[i][j] = (combo[i-1][j-1] + combo[i-1][j])%MOD;
	
		// 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.
			int n = stdin.nextInt();
			int target = stdin.nextInt();
			
			// Store ranges here.
			int[] low = new int[n];
			int[] high = new int[n];
			int minSum = 0, maxSum = 0;
			for (int i=0; i<n; i++) {
				low[i] = stdin.nextInt();
				high[i] = stdin.nextInt();
				minSum += low[i];
				maxSum += high[i];
			}
			
			// Screen out impossible case.
			if (maxSum < target || minSum > target) {
				System.out.println("0");
				continue;
			}
			
			// Just put these required ornaments on the tree.
			target -= minSum;
			
			// Now, store how many ornaments of each type we are free to choose.
			int[] range = new int[n];
			for (int i=0; i<n; i++)
				range[i] = high[i] - low[i];
				
			// If there were no restrictions, then there are combo(n+r-1,r-1) ways
			// to choose the ornaments - combinations with repetition formula.
			
			// Pre-comp here will store sum of ranges for a mask. So maskTotal[13] 
			// will store (range[0]+1) + (range[2]+1) + (range[3]+1), since 13 = 1101 in binary.
			// The +1 is because we subtract out all impossible solutions, where we have too much
			// of a particular ornament.
			int[] maskTotal = new int[1<<n];
			
			// Store result here.
			long res = 0;
			
			// Here, we will use inclusion-exclusion principle to adjust for all upper bounds.
			for (int mask=0; mask<(1<<n); mask++) {
				
				// This is an important value for inclusion-exclusion.
				int bitsOn = Integer.bitCount(mask);
				
				// Have to update this mask's total.
				if (bitsOn > 0) {
					int lowbit = lowestOneBit(mask);
					maskTotal[mask] = maskTotal[mask-(1<<lowbit)] + range[lowbit] + 1;
				}
				
				// Too many ornaments to get to this case.
				if (maskTotal[mask] > target) continue;
				
				// This is my target for this case.
				int tempTarget = target - maskTotal[mask];
				
				// Our term to add or subtract, using the previously stated formula.
				long term = combo[tempTarget+n-1][n-1];
				
				// Add or subtract, depending on set size.
				if (bitsOn%2 ==0) 	res = (res + term)%MOD;
				else				res = (res - term + MOD)%MOD;
			}
			
			// Ta da!
			System.out.println(res);
		}
	}
	
	// Returns lowest bit location (not value) that is on.
	public static int lowestOneBit(int n) {
		int i = 0;
		while ((n & (1<<i)) == 0) i++;
		return i;
	}
}