House Arrest
Difficulty: Hard

After suddenly getting an illness that required him to use a wheel chair, the Supreme Court decided to put Jejeman under house arrest instead of the normal prison.

According to the Constitution, the lot (the house including the garden and everything) where Jejeman will be banished to will have some constraints.

First, the total land area of the lot must be exactly $A$ square meters. This is because less than $A$ square meters of space will worsen Jejeman's illness (according to doctors he enlisted). No one wants him to die of course since he gives people birthday cakes! Moreover, it must not exceed $A$ square meters, otherwise people will think that he's not being punished for his misdeeds.

Of course, no one is supposed to visit Jejeman. Thus, there must be some sort of fencing. The budget for this is enough for $P$ meters worth of fencing material. Needless to say, $P$ meters worth of material should be able to fence an area of exactly $A$ square meters. It has to be exactly that, otherwise the contractor will not install it.

Moreover, the lot he chooses must be one contiguous land area. This is common sense. If he makes it more than one contiguous land areas, then he would not be able to access both of them since he's not supposed to be outside the alloted area for him. Furthermore, there shouldn't be any "holes" in the area. The lot will also be a corner lot (between perpendicular streets). Hence, to make things beautiful, all fencing material must be parallel to any of the two streets.

The following image shows examples of plans which are valid and invalid:
<img src="https://s3.amazonaws.com/hr-challenge-images/5443/1428600624-67a4c72b56-Final-HouseArrest.jpg" title="Final - House Arrest.jpg" />

To summarize, the whole lot, when viewed from Jejeman's helicopter hovering in the sky must be a polygon. The architect assigned to do this is at a loss. Perhaps the perfect lot shape could be found using programming?


Input Format:
The first line of input contains $C$, the number of test cases. The following lines describe the test cases.

Each test case consists of one line containing two integers, $A$ and $P$, as discussed above.





Output Format:
For each test case, output `WALA` if there is no polygon satisfying all the above. 

Otherwise, write $M$ in the first line, where $M$ is the number of corners of the polygon. In the next $M$ lines, write the coordinates $(x_i, y_i)$ of the corners (in either order around the polygon). Naturally, $(x_M, y_M)$ is assumed to be connected to $(x_1, y_1)$. To keep things simple, no three consecutive points must lie on the same line. To keep things simpler, we limit the number of corners $M$ to be at most $50$. Moreover, the $x_i$'s and $y_i$'s must be *integers* satisfying the constraints written below.

We assume that the two perpendicular streets described in the problem statement are parallel to the $x$ and $y$ axes.

Take note that this polygon is not unique. We will accept any answer which satisfies the conditions.

**Constraints**  
For any $i \in \{1, \ldots, M\}$  
$-10^{15} \leq x_i \le 10^{15}$  
$-10^{15} \leq y_i \le 10^{15}$  

**Subtask 1** (4 points each):  
$1 \le C \le 1000$  
$1 \le A \le 5$  
$1 \le P \le 20$  

**Subtask 2** (8 points each):  
$1 \le C \le 1000$  
$1 \le A \le 30$  
$1 \le P \le 300$  

**Subtask 3** (11 points each):  
$1 \le C \le 1000$  
$1 \le A \le 10000$  
$1 \le P \le 10000$  

**Subtask 4** (13 points each):  
$1 \le C \le 5000$  
$1 \le A \le 10^9$  
$1 \le P \le 10^9$  

**Subtask 5** (14 points each):  
$1 \le C \le 5000$  
$1 \le A \le 10^{16}$  
$1 \le P \le 10^{16}$  


Sample Input:
    3
    4 8
    3 8
    1 20

Sample Output:
    4
    1 1
    1 -1
    -1 -1
    -1 1
    6
    0 0
    2 0
    2 1
    1 1
    1 2
    0 2
    WALA

Python 3 starter code:


Reference solution (C++):
```c++
#include <stdio.h>
#include <math.h>
#include <set>
using namespace std;

#define ll long long
#define BD (2000000000000000LL-10) // 2*10^15 - 10
#define DL 1000000000000000LL // 10^15

// computes the integer square root
ll isqrt(ll n) {
    ll s = int(sqrt(n));
    while (s * s < n) s += 1;
    while (s * s > n) s -= 1;
    return s;
}

ll xs[1111];
ll ys[1111];

ll min(ll a, ll b) { return a < b ? a : b; }

int ans(ll a, ll p) {

    // odd perimeter: impossible
    if (p % 2) {
        return 0;
    }
    // too large perimeter
    if (p > 2*a + 2) {
        return 0;
    }
    ll s = isqrt(a);
    ll inner = (s-1)*(s-1);
    if (s * (s+1) < a) {
        inner += s-1 + a - s*(s+1) - 1;
    } else if (s * s < a) {
        inner += a - s*s - 1;
    }
    // too small perimeter
    ll min_p = 2*a - 2*inner + 2;
    if (p < min_p) {
        return 0;
    }

    int ct = 0;
    #define addpt(x,y) (xs[ct] = (x), ys[ct] = (y), ct++)

    // trivial case, a = 1
    if (a == 1) {
        addpt(0,0);
        addpt(0,1);
        addpt(1,1);
        addpt(1,0);
        return ct;
    }

    // create a polygon with minimum perimeter
    // and with the desired number of interior points
    inner = a - p/2 + 1;
    s = isqrt(inner) + 1;
    if (inner == 0) {
        // no inner points
        addpt(0,0);
        addpt(1,0);
        addpt(1,2);
        addpt(0,2);
    } else if (inner > (s-1)*s) {
        // oblong rectangle + incomplete layer 
        ll x = inner - (s-1)*s + 1;
        addpt(0,0);
        addpt(s+1,0);
        addpt(s+1,s);
        addpt(x,s);
        addpt(x,s+1);
        addpt(0,s+1);
    } else if (inner == (s-1)*s) {
        // oblong rectangle
        addpt(0,0);
        addpt(s+1,0);
        addpt(s+1,s);
        addpt(0,s);
    } else if (inner > (s-1)*(s-1)) {
        // square + incomplete layer
        ll y = inner - (s-1)*(s-1) + 1;
        addpt(0,0);
        addpt(s,0);
        addpt(s,s);
        addpt(y,s);
        addpt(y,s+1);
        addpt(0,s+1);
    } else {
        // square
        addpt(0,0);
        addpt(s,0);
        addpt(s,s);
        addpt(0,s);
    }

    // compute the current area, using area formula
    ll A = 0;
    for (int i = 0, j = ct - 1; i < ct; j = i++) {
        A += xs[i] * ys[j] - xs[j] * ys[i];
    }
    if (A < 0) A = -A;
    A /= 2;

    // if a > A, then we need to add a few more blocks
    // WITHOUT adding new interior points (so we get 
    // the desired perimeter)

    while (a > A) {
        #define move(_i,ch) do {\
            for (int i = ct-1; i >= _i; i--) {\
                xs[i+ch] = xs[i];\
                ys[i+ch] = ys[i];\
            }\
            ct += ch;\
        } while (0)
        #define insertpt(i,x,y) (xs[i] = (x), ys[i] = (y))

        ll x1 = xs[1], y1 = ys[1];
        ll x2 = xs[2], y2 = ys[2];
        ll d = min(a - A, BD);
        // add a J branch with height d
        if (d <3) {
            // height-1 branch
            move(2, 2);
            insertpt(1,x1 + d,0);
            insertpt(2,x1 + d,1);
            insertpt(3,x1,1);
            A += d;
        } else {
            // tall branch
            move(2, 4);
            insertpt(1,x1 + 2,0);
            insertpt(2,x1 + 2,d-1);
            insertpt(3,x1 + 1,d-1);
            insertpt(4,x1 + 1,1);
            insertpt(5,x1,1);
            A += d;
        }
    }

    // adjust points
    ll mx = xs[0], my = ys[0];
    for (int i = 0; i < ct; i++) {
        ll x = xs[i], y = ys[i];
        mx = min(mx, x);
        my = min(my, y);
    }
    mx += DL;
    my += DL;
    for (int i = 0; i < ct; i++) {
        xs[i] -= mx;
        ys[i] -= my;
    }

    return ct;
}

int main() {
    int z;
    scanf("%d", &z);
    while (z--) {
        ll a, p;
        scanf("%lld%lld", &a, &p);
        int ct = ans(a,p);
        if (!ct) {
            printf("WALA\n");
        } else {
            printf("%d\n", ct);
            for (int i = 0; i < ct; i++) {
                ll x = xs[i];
                ll y = ys[i];
                printf("%lld %lld\n", x, y);
            }
        }
    }
}
```