Mixing flavors

All submissions for this problem are available.
Please refer to sample test in English version of statement.
Except for that, you can read problem statement in Mandarin Chinese, Russian and Vietnamese.
There are N icecreams placed in a row in a shop, where the ith has cost C[i] and flavor F[i]. Chef wants to buy some consecutive segment of icecreams so that their total cost doesn't exceed his budget K, and he can mix some subset of bought icecreams to make a new icecream with maximum possible flavor.
Mixing m icecreams of flavors A_{1}, A_{2}, .., A_{m} will result in an icecream of flavor equal to A_{1} ^ A_{2} ^ ... ^ A_{m} where ^ is the xor operation.
What is maximum possible flavor that Chef can get? It's guaranteed that at least one icecream has cost that doesn't exceed Chef's budget.
Input
First line contains an integer T, which is the number of testcases.
The first line of each testcase contains two integers: N and K.
Each of the following N lines contains two integers C[i] and F[i].
Output
Output the answer of each testcase in new line, the maximum flavor that the Chef can get.
Constraints
 1 ≤ T ≤ 10,000
 1 ≤ N ≤ 100,000
 sum of N in all testcases will not exceed 100,000
 1 ≤ K ≤ 10^14
 1 ≤ F[i] ≤ 10^9
 1 ≤ C[i] ≤ 10^9
 C[i] ≤ K for at least one i
Example
Input: 2 5 15 2 4 7 1 5 9 15 6 3 12 3 1000 123 8 99999 1 80 7 Output: 13 8
Explanation
Test case 1: The binary representations of the 5 flavors, in order, are: (0100, 0001, 1001, 0110, 1100), and the corresponding prices are (2,7,5,15,3).
If Chef buys only the 5^{th} icecream with cost 3 and flavor 12. But if Chef buys the first 3 icecreams, his total cost is 2+7+5 = 14, which is within his budget of 15, and hence valid. Now, from these three bought icecreams, he can choose to mix just the first and third, and get a flavor of 0100^1001 = 1101, which is 13. You can verify that this is the best that he can do.
Test case 2: Chef can afford the first or the last icecream. He could afford them both but he must buy a consecutive segment of icecreams while the cost of the second icecream is beyond his budget.
It's optimal to buy the first icecream only and use its flavor only, what gives us the answer 8.
Author:  kingofnumbers 
Tester:  errichto 
Editorial  https://discuss.codechef.com/problems/MIXFLVOR 
Tags  cook79, gausselim, kingofnumbers, mediumhard, twopointers 
Date Added:  31012017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 