/*
-----------------------------------------------------------------------------
Author : ---------------------------------------------------------
UTKAR$H $AXENA ---------------------------------------------------------
IIT INDORE ---------------------------------------------------------
-----------------------------------------------------------------------------
*/
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fre freopen("0.in","r",stdin),freopen("0.out","w",stdout)
#define abs(x) ((x)>0?(x):-(x))
#define M 1000000007
#define lld signed long long int
#define pp pop_back()
#define ps(x) push_back(x)
#define mpa make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define scan(x) scanf("%d",&x)
#define scanll(x) scanf("%lld",&x)
#define printll(x) printf("%lld\n",x)
#define boost ios_base::sync_with_stdio(0)
//vector<int> g[2*100000+5];int par[2*100000+5];
struct mat
{
int m[32][32];
int N=30;
mat()
{
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
m[i][j]=0;
}
mat(int i)
{
//identity
for(int i=1;i<=N;++i)
for(int j=1;j<=N;++j)
m[i][j]=0;
for(int i=1;i<=N;++i)
m[i][i]=1;
}
~mat() { }
}G;
int N;
mat mul(mat a,mat b)
{
mat c;
for(int i=1;i<=N;++i)
{
for(int j=1;j<=N;++j)
{
for(int k=1;k<=N;++k)
{
c.m[i][j]+=(((lld)a.m[i][k])*b.m[k][j])%M;
c.m[i][j]%=M;
}
}
}
return c;
}
mat pow(mat base, lld exponent)
{
mat result(1);
while (exponent > 0)
{
if (exponent % 2 == 1)
result = mul(result , base);
exponent = exponent >> 1;
base = mul(base , base);
}
return result;
}
mat add(mat a,mat b)
{
for(int i=1;i<=N;++i)
{
for(int j=1;j<=N;++j)
{
a.m[i][j]=(a.m[i][j]+b.m[i][j])%M;
}
}
return a;
}
mat rec(lld S)
{
if(S==1)
return G;
if(S%2==1)
return add(pow(G,S),rec(S-1));
mat temp=pow(G,S/2);
for(int i=1;i<=N;++i)
temp.m[i][i]=(temp.m[i][i]+1)%M;
return mul(rec(S/2),temp);
}
void print(mat A)
{
for(int i=1;i<=N;++i)
{
for(int j=1;j<=N;++j)
{
cout<<A.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