Chef and math

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it is an element of Chefonacci sequence defined as follows.
f(0) = 1;
f(1) = 2;
For i > 1 : f(i) = f(i  1) + f(i  2)
Chef asked you to help him with this task. There will be Q question of form X, K : How many different ways are there to create X by adding K Chefonacci numbers. Note that the order of numbers in the addition does not matter, i.e. (f(i) + f(j) + f(k)) and (f(j) + f(i) + f(k)) will not be counted as distinct ways. Also note that you are allowed to use a Chefonacci number any number of times (zero or more).
As the answer could be large, print your answer modulo 10^{9} + 7 (1000000007).
Input
First line of the input contains an integer Q denoting number of questions Chef was asked.
In the next Q lines follow the questions, ith of the line will denote the ith question represented by two space separated integer X, K respectively.
Output
For each question, output a separate line containing the answer of the question.
Constraints and Subtasks

Subtask 1 : [10 points]
 1 ≤ Q ≤ 50
 1 ≤ X ≤ 10^{9}
 1 ≤ K ≤ 4
 1 ≤ Q ≤ 100
 1 ≤ X ≤ 10^{9}
 1 ≤ K ≤ 5
 1 ≤ Q ≤ 100
 1 ≤ X ≤ 10^{2}
 1 ≤ K ≤ 10
 1 ≤ Q ≤ 100
 1 ≤ X ≤ 10^{9}
 1 ≤ K ≤ 10
Subtask 2 : [20 points]
Subtask 3 : [20 points]
Subtask 4 : [50 points]
Example
Input: 5 12 1 13 1 13 2 13 3 13 4 Output: 0 1 1 2 4
Explanation
Example case 1.
There is no way to create 12 by adding one Chefonacci number, as 12 is not a Chefonacci number.
Example case 2.
There is only one way to create 13 by adding one Chefonacci number, i.e. 13.
Example case 3.
There is one way to create 13 by adding two Chefonacci numbers, i.e. 5 + 8.
Example case 4.
There are two ways to create 13 by adding three Chefonacci numbers: 2 + 3 + 8, 3 + 5 + 5.
Example case 5.
There are four ways to create 13 by adding four Chefonacci numbers: 1 + 1 + 3 + 8, 1 + 2 + 2 + 8, 1 + 2 + 5 + 5, 2 + 3 + 3 + 5
Author:  omelyanenko 
Tester:  kevinsogo 
Editorial  http://discuss.codechef.com/problems/CHEFMATH 
Tags  dynamicprogramming, easymedium, may16, meetinmiddle, omelyanenko, recursion 
Date Added:  9022016 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, 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. 