// Arup Guha
// 1/27/2020
// Alternate Solution to 2020 Mercer Programming Contest Problem: Leap Day Dinner

import java.util.*;

public class leapday_arup {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process call cases.
		for (int loop=0; loop<numCases; loop++) {
			
			int n = stdin.nextInt();
			int threshold = stdin.nextInt();
		
			int[] timeM = new int[n];
			int[] votes = new int[n];
			int sumT = 0;
			
			// Read in the time and votes for each.
			for (int i=0; i<n; i++) {
				timeM[i] = stdin.nextInt();
				votes[i] = stdin.nextInt();
				sumT += timeM[i];
			}
			
			// Run Knapsack DP with time = weights, votes = values.
			int[] dp = new int[sumT+1];
			for (int i=0; i<n; i++)
				for (int j=sumT; j>=timeM[i]; j--)
					dp[j] = Math.max(dp[j], dp[j-timeM[i]] + votes[i]);
				
			// Find smallest time value that works.
			int res = sumT;
			for (int i=sumT; i>=0; i--)
				if (dp[i] >= threshold)
					res = i;
				
			// Ta da!
			System.out.println(res);
		}
	}
}