This page is still under construction.

Parts of this page are still being built. What you see may change.

Atomic Computer

Time limit1sMemory limit256 MB

Summary
Count the length-y signed-binary strings over -1, 0 and 1 whose digits weighted by powers of two sum to x.
Level

Medium5 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

A professor has built the Atomic Computer, which runs 8,000,000,000 times faster than a normal computer. It keeps values in a special memory where one bit represents one of three states, -1, 0 and 1.

Write the bits of a yy bit memory as dy−1,dy−2,…,d1,d0d_{y-1}, d_{y-2}, \dots, d_1, d_0, starting from the front. The value held by the memory is

∑i=0y−1di⋅2i\sum_{i=0}^{y-1} d_i \cdot 2^{i}

Each did_i is -1, 0 or 1. For example, (1)(−1)(0)2(1)(-1)(0)_2 holds 1⋅4+(−1)⋅2+0⋅1=21 \cdot 4 + (-1) \cdot 2 + 0 \cdot 1 = 2. The number of bits is always exactly yy, and a representation whose leading bits are 0 counts as its own way of storing the value.

Given an integer xx to store and the number of bits yy, count the ways to store xx in yy bits.

Input

The first line contains the number of test cases TT. (T≥1T \ge 1)

Each of the next TT lines contains two integers xix_i and yiy_i, where xix_i is the value to store and yiy_i is the number of bits. (−2000000000≤xi≤2000000000-2000000000 \le x_i \le 2000000000, 1≤yi≤201 \le y_i \le 20)

Output

Print TT lines. The iith line contains the number of ways to store xix_i in yiy_i bits.

Examples2

  1. Example 1

    Input
    1
    1 2
    
    Expected output
    2
    
  2. Example 2

    Input
    2
    -2 1
    -2 2
    
    Expected output
    0
    1