#include<bits/stdc++.h>
using namespace std;
#define int long long
int t[6][10]={//t[i][j]=2^(j*10^i)%10007
{1,2,4,8,16,32,64,128,256,512},//i=0
{1,1024,7848,731,8026,2877,3990,2904,1617,4653},//1
{1,1340,4347,906,3193,5631,262,835,8123,7211},//2
{1,5985,5172,2769,873,1251,1999,5650,1597,1360},//i=3
{1,3909,-408,6248,6352,2601,197,9541,9687,-5},
{1,469}
};
signed main(){
int a;
while(cin>>a){
int s=1;a--;
//for(int i=0;i<a;i++)s=(s*2)%10007;
//cout<<","<<s;
for(int i=0;a>0;i++)s=(s*t[i][a%10])%10007,a=a/10;
cout<<(s+10007)%10007<<"\n";
}
}
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t[6][10]={//t[i][j]=2^(j*10^i)%10007
{1,2,4,8,16,32,64,128,256,512},//i=0
{1,1024,7848,731,8026,2877,3990,2904,1617,4653},//1
{1,1340,4347,906,3193,5631,262,835,8123,7211},//2
{1,5985,5172,2769,873,1251,1999,5650,1597,1360},//i=3
{1,3909,-408,6248,6352,2601,197,9541,9687,-5},
{1,469}
};
signed main(){
int a;
while(cin>>a){
int s=1;a--;
//for(int i=0;i<a;i++)s=(s*2)%10007;
//cout<<","<<s;
for(int i=0;a>0;i++)s=(s*t[i][a%10])%10007,a=a/10;
cout<<(s+10007)%10007<<"\n";
}
}
還好阿 沒有很笨 我連要AC都有點困難...