#include<iostream>
#include<map>
#include<vector>
#include<string>

#define BIGMODE 1000000007

using namespace std;

struct SM{
	string wild;
	int reminder;
	bool operator<(const SM& A) const
    { 
    	if(wild == A.wild)
    		return reminder<A.reminder;
    	return wild<A.wild; 
    }
};

string tar;
map<SM, int> dicMap;
long long curAns[13];
long long oldAns[13];


SM createSM(string s, int r){
	SM sm;
	sm.wild = s;
	sm.reminder = r;
	return sm;
}

vector<string> dicKeys(){
	string digits[11] = {"1","2","3","4","5","6","7","8","9","0","?"};
	vector<string> v;
	string temp = "";
	for (int i = 0; i < 11; ++i)
	{
		for (int j = 0; j < 11; ++j)
		{
			for (int k = 0; k < 11; ++k)
			{
				temp = "" + digits[i] + digits[j] +digits[k];
				v.push_back(temp); 
			}
		}
	}
	return v;
}

void printV(vector<string> v){
	for (int i = 0; i < v.size(); ++i)
		cout << v[i]<<endl;
}

string Stringify(int x){
	string s;
	if(x == 0)
		s = "000";
	else if(x < 10) 
		s = "00" + to_string(x);
	else if(x < 100) 
		s = "0" + to_string(x);
	else if(x < 1000) 
		s = to_string(x);
	return s;
}

bool isMatch(string w, int x){
	string s = Stringify(x);
	for (int i = 0; i < s.length(); ++i)
		if(s[i] != w[i] && w[i] != '?')
			return false;
	return true;
}

vector<SM> getWildcards(int x){
	string s = Stringify(x);
	vector<SM> v;
	int mod = x%13;
	v.push_back(createSM(string() + s[0] + s[1] + s[2],mod));
	v.push_back(createSM(string() + "?" + s[1] + s[2],mod));
	v.push_back(createSM(string() + s[0] + "?" + s[2],mod));
	v.push_back(createSM(string() + s[0] + s[1] + "?",mod));
	v.push_back(createSM(string() + "??" + s[2],mod));
	v.push_back(createSM(string() + "?" + s[1] + "?",mod));
	v.push_back(createSM(string() + s[0] + "??",mod));
	v.push_back(createSM(string() + "???",mod));

	return v;
}

map<SM,int> initMap(vector <string> v){
	map<SM,int> m;
	for (int i = 0; i < v.size(); ++i)
	{
		for (int j = 0; j < 13; ++j)
		{
			SM temp;
			temp.wild = v[i].c_str();
			temp.reminder = j;
			m.insert(std::pair<SM,int>(temp,0));
		}
	}
	return m;
}

int getModulo(int x){
	if(x < 0) x +=13;
	else x %=13;
	return x;
}


long long doCalc(int l, int r, int m){
	if(r - l > 3){
		long long res = 0;
		for (int i = 0; i < 13; ++i)
		{
			res +=(doCalc(l,r-3,i)%BIGMODE)*(doCalc(r-3,r,getModulo(m+i))%BIGMODE);
			res = res%BIGMODE;
		}
		return res;
	}
	SM mySM;
	mySM.wild = tar.substr(l,r-l);
	mySM.reminder = m;
	return dicMap[mySM];
}


int main () {
	std::vector<string> v = dicKeys();
	dicMap = initMap(v);
	for (int i = 0; i < 1000; ++i)
	{

		vector<SM> smV = getWildcards(i);

		for (int j = 0; j < smV.size(); ++j)
		{
			 dicMap[smV[j]] = dicMap[smV[j]] + 1;
			 // if(i == 1) cout << smV[j].wild<<endl; 
		}
	}


	cin >> tar;
	bool firstIt = true;
	int evenCounter = 0;

	for (int i = tar.size()-1; i > -1; i = i - 3)
	{
		for (int j = 0; j < 13; ++j)
			oldAns[j] = curAns[j];

		string curS = "";
		if(i > 2) curS = tar.substr(i-2,3);
		else{
			curS = tar.substr(0,i+1);
			if(i == 1) curS = "0"+curS;
			if(i == 0) curS = "00" +curS;  		
		} 
		for (int j = 0; j < 13; ++j)
		 {	
		 	if(firstIt){
		 		SM tempSM;
		 		tempSM.wild = curS;
		 		tempSM.reminder = j;
		 		curAns[j] = dicMap[tempSM];
		 	}
		 	else{
		 		curAns[j] = 0;
		 		for (int k = 0; k < 13; ++k)
		 		{
		 			SM tempSM;
		 			tempSM.wild = curS;
		 			tempSM.reminder = k;
		 			if(evenCounter%2 == 1)
		 				curAns[j] +=  (oldAns[getModulo(k+j)]*dicMap[tempSM])%BIGMODE;
		 			else 
		 				curAns[j] +=  (oldAns[getModulo(j-k)]*dicMap[tempSM])%BIGMODE;
		 			curAns[j] = curAns[j]%BIGMODE;
		 		}
		 	}
		 }
		 firstIt = false;
		 evenCounter++;
	}
	cout << curAns[5]<<endl;

	
	return 0;
}

Measured memory_bytes: 2432