human
Can you solve the below in PYTHON3?
A known chef has prepared n dishes: the i-th dish consists of a_i grams of fish and b_i grams of meat. 

The banquet organizers estimate the balance of n dishes as follows. The balance is equal to the absolute value of the difference between the total mass of fish and the total mass of meat.

Technically, the balance equals to \left|∑_{i=1}^n a_i - ∑_{i=1}^n b_i\right|. The smaller the balance, the better.

In order to improve the balance, a taster was invited. He will eat exactly m grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he should eat exactly m grams of each dish in total.

Determine how much of what type of food the taster should eat from each dish so that the value of the balance is as minimal as possible. If there are several correct answers, you may choose any of them.

Input

The first line of input data contains an integer t (1 ≤ t ≤ 10^4) — the number of the test cases.

Each test case's description is preceded by a blank line. Next comes a line that contains integers n and m (1 ≤ n ≤ 2 ⋅ 10^5.
0 ≤ m ≤ 10^6). The next n lines describe dishes, the i-th of them contains a pair of integers a_i and b_i (0 ≤ a_i, b_i ≤ 10^6) — the masses of fish and meat in the i-th dish.

It is guaranteed that it is possible to eat m grams of food from each dish. In other words, m ≤ a_i+b_i for all i from 1 to n inclusive.

The sum of all n values over all test cases in the test does not exceed 2 ⋅ 10^5.

Output

For each test case, print on the first line the minimal balance value that can be achieved by eating exactly m grams of food from each dish.

Then print n lines that describe a way to do this: the i-th line should contain two integers x_i and y_i (0 ≤ x_i ≤ a_i.
0 ≤ y_i ≤ b_i.
x_i+y_i=m), where x_i is how many grams of fish taster should eat from the i-th meal and y_i is how many grams of meat.

If there are several ways to achieve a minimal balance, find any of them.

Example

Input

8

1 5
3 4

1 6
3...

=====
What is a Python code to find any of them?
assistant
#Here is Python code to find any of them.

import io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main(t):

    space = input()
    n,req = map(int,input().split())
    tempmin = []
    tempmax = []
    temp = []

    ans = []
    def getab(i,diff):

        ans.append([(req-diff+temp[i][0]-temp[i][1])//2,(req+diff+temp[i][1]-temp[i][0])//2 ])


    for i in range(n):
        maxa,maxb = map(int,input().split())
        temp.append([maxa,maxb])
        if req>maxb:  
            maxdiff = maxa - (req-maxb)
        else:
            maxdiff = maxa - (maxb-req)

        if req>maxa:
            mindiff = 0 - ( maxb - (req-maxa))
        else:
            mindiff = maxa-req - maxb


        tempmin.append(mindiff)
        tempmax.append(maxdiff)

    minimum = sum(tempmin)
    needed = -minimum

    for i in range(n):
        if needed >= tempmax[i]-tempmin[i]:
            getab(i,tempmax[i]) 
            needed -= tempmax[i]-tempmin[i]
        elif needed >= 0:
            if needed%2==1:  
                getab(i,tempmin[i]+needed-1)
                needed = 1
            else:
                getab(i,tempmin[i]+needed)
                needed = 0
        else:
            getab(i,tempmin[i])

    print(abs(needed))
    for sub in ans:
        print(sub[0],sub[1])

            
        
            




















T = int(input())
t = 1
while t<=T:
    main(t)
    t += 1