Under construction

Still being built. Things may change

Compositions Missing a Sequence

Interview

Time limit1sMemory limit256 MB

Summary
Count the ordered compositions of n that use no part from the arithmetic progression starting at m with step k.
Level

Easy3 of 10

Topics
Dynamic programming, Combinatorics
Solved
No attempts yet

Problem

A composition of an integer nn is an ordered list of positive integers whose sum is nn. Two compositions that use the same numbers in a different order count as different, which is what separates compositions from partitions. Written out in full, the compositions of the first few integers are:

1: {1}
2: {1+1, 2}
3: {1+1+1, 1+2, 2+1, 3}
4: {1+1+1+1, 1+1+2, 1+2+1, 1+3, 2+1+1, 2+2, 3+1, 4}

For 3, the compositions 1+2 and 2+1 are counted separately. As you may have guessed, an integer nn has 2n−12^{n-1} compositions.

This problem puts a condition on the numbers a composition uses. A composition misses a set SS when no number in the composition belongs to SS. The compositions of the first few integers that miss the set of even integers are:

1: {1}
2: {1+1}
3: {1+1+1, 3}
4: {1+1+1+1, 1+3, 3+1}

No odd integer has a composition that misses the set of odd integers, and every composition of an even integer nn into even numbers alone pairs off with a composition of n/2n/2 multiplied by 2.

Write a program that counts the compositions of nn which miss the arithmetic sequence {m+ik∣i=0,1,2,… }\{m + ik \mid i = 0, 1, 2, \dots\}.

Input

The first line contains one integer PP, the number of data sets (1≤P≤100001 \le P \le 10000). Each data set is processed the same way and independently of the others.

Each of the next PP lines holds one data set. A line contains the data set number KK, followed by the three space separated integers nn, mm and kk (1≤n≤301 \le n \le 30, 0≤m<k<300 \le m < k < 30).

Output

Print one line for each data set. The line contains the data set number KK, a single space, then the number of compositions of nn which miss the given sequence.

Examples3

  1. Example 1

    Input
    3
    1 10 0 2
    2 15 1 4
    3 28 3 7
    
    Expected output
    1 55
    2 235
    3 18848806
    
  2. Example 2

    Input
    4
    1 1 0 1
    2 1 0 2
    3 1 1 2
    4 1 0 29
    
    Expected output
    1 0
    2 1
    3 0
    4 1
    
  3. Example 3

    Input
    6
    1 2 1 2
    2 3 1 2
    3 29 1 2
    4 30 1 2
    5 4 1 2
    6 16 1 2
    
    Expected output
    1 1
    2 0
    3 0
    4 16384
    5 2
    6 128