Girlfriend & Necklace
Difficulty: Hard

Mr. X wants to buy a necklace for his girlfriend.
The available necklaces are bi-colored (red and blue beads).

Mr. X desperately wants to impress his girlfriend and knows that she will like the necklace only if **every prime length continuous sub-sequence of beads in the necklace** has more or equal number of red beads than blue beads.

Given the number of beads in the necklace N, Mr. X wants to know the number of all possible such necklaces.

_Note: - It is given that the necklace is a single string and not a loop._


**Input Format**  
The first line of the input contains an integer *T*, the number of testcases.  
*T* lines follow, each line containing *N*, the number of beads in the necklace.  

**Constraints**  
1 &le; T &le; 10<sup>4</sup>  
2 &le; N &le; 10<sup>18</sup>  

**Output Format**  
For each testcase, print in a newline, the number of such necklaces that are possible.  If the answer is greater than or equal to 10<sup>9</sup>+7, print the answer modulo ( % ) 10<sup>9</sup>+7.

**Sample Input**

    2
    2
    3

**Sample Output**

    3
    4

**Explanation**

For the first testcase, valid arrangement of beads are 

    BR RB RR

For the second testcase, valid arrangement of beads are

    BRR RBR RRR RRB

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
###C++  
```cpp  
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
#define MOD 1000000007
#define LL  long long
int i,j;
void multiplyMM(LL F[3][3], LL M[3][3])
{
    LL l[3][3];
    
    l[0][0]=((F[0][0]*M[0][0])%MOD+(F[0][1]*M[1][0])%MOD+(F[0][2]*M[2]    [0])%MOD)%MOD;
    l[0][1]=((F[0][0]*M[0][1])%MOD+(F[0][1]*M[1][1])%MOD+(F[0][2]*M[2][1])%MOD)%MOD;
    l[0][2]=((F[0][0]*M[0][2])%MOD+(F[0][1]*M[1][2])%MOD+(F[0][2]*M[2][2])%MOD)%MOD;
    l[1][0]=((F[1][0]*M[0][0])%MOD+(F[1][1]*M[1][0])%MOD+(F[1][2]*M[2][0])%MOD)%MOD;
    l[1][1]=((F[1][0]*M[0][1])%MOD+(F[1][1]*M[1][1])%MOD+(F[1][2]*M[2][1])%MOD)%MOD;
    l[1][2]=((F[1][0]*M[0][2])%MOD+(F[1][1]*M[1][2])%MOD+(F[1][2]*M[2][2])%MOD)%MOD;
    l[2][0]=((F[2][0]*M[0][0])%MOD+(F[2][1]*M[1][0])%MOD+(F[2][2]*M[2][0])%MOD)%MOD;
    l[2][1]=((F[2][0]*M[0][1])%MOD+(F[2][1]*M[1][1])%MOD+(F[2][2]*M[2][1])%MOD)%MOD;
    l[2][2]=((F[2][0]*M[0][2])%MOD+(F[2][1]*M[1][2])%MOD+(F[2][2]*M[2][2])%MOD)%MOD;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            {
                F[i][j]=l[i][j];
            }
      }
}

void multiplyMF(LL m[3][3],LL a[3])
{
    LL x =((a[0]*m[0][0])%MOD+((a[1]*m[0][1])%MOD)+((a[2]*m[0][2])%MOD))%MOD;
    LL y =((a[0]*m[1][0])%MOD+((a[1]*m[1][1])%MOD)+((a[2]*m[1][2])%MOD))%MOD;
    LL z =((a[0]*m[2][0])%MOD+((a[1]*m[2][1])%MOD)+((a[2]*m[2][2])%MOD))%MOD;
    a[0]=x;
    a[1]=y;
    a[2]=z;
}

void powerM(LL f[3][3],LL n)
{
    if(n==0||n==1||n<0)
    return;
    LL M[3][3]={{0,0,1},{1,0,0},{0,1,1}};
    powerM(f, n/2);
    multiplyMM(f,f);
    if(n%2!=0)
    multiplyMM(f, M);
}
LL func(LL n)
{
    LL f[3]={1,1,1};
    if(n<3)
    return f[n];
    LL M[3][3]={{0,0,1},{1,0,0},{0,1,1}};
    powerM(M,n-1);
    multiplyMF(M,f);
    return(f[0]);
}
LL N;
int main()
{
  // freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>N;
        if(N==0 || N==1)
        cout<<"0"<<endl;    
        else
        cout<<func(N+2)<<endl;
    }
    return 0;
}
```