#include<stdio.h>
#include<string.h>
int max(int a, int b)
{
return (a > b ? a : b);
}
int main()
{
int m;
scanf("%d",&m);
while(m--)
{
int n, w;
scanf("%d%d",&n,&w);
int weight[10000] = {0}, value[10000] = {0}, dp[200000], i, j;
memset(dp,-0x3f,sizeof(dp));
dp[0] = 0;
for (i = 1; i <= n; i++)
scanf("%d%d",&weight[i], &value[i]);
for (i = 1; i <= n; i++)
{
for (j = weight[i]; j <= w; j++)
{
dp[j] = max(dp[j], dp[j-weight[i]] + value[i]);
}
}
if(dp[w] >= 0)
printf("%d\n",dp[w]);
else
printf("NO\n");
}
return 0;
}