#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int OO = 1e9+7 ,N=2e5+5;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; // dir array
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
void File(){
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
int fix_mod(int x){
return(x%4 +4)%4;
}
int solve(){
string s;cin>>s;
int n=s.size(),q;
vector<vector<int>>pre(5,vector<int>(n+1));
for(int i=0;i<n;i++){
pre[i%4][i] = (s[i]=='1');
}
for(int i=0;i<4;i++){
for(int j=0;j<n;j++){
if(j)pre[i][j]+=pre[i][j-1];
cout<<pre[i][j]<<' ';
}
cout<<endl;
}
cin>>q;
while(q--){
int l,r;cin>>l>>r;
l--,r--;
int sum =s[r]=='1';
for(int i=1;i<=4&& r-i>=l;i++){
int x= fix_mod(r-i);
int y;
if(l)y=pre[x][l-1];
else y=0;
sum+= (pre[x][r-i] -y)* pow(2,i) ;
sum%=10;
}
cout<<sum<<'\n';
}
return 0;
}
int main() {
File();
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
// int t,i=1;cin>>t;
// while(t--)
solve();
}
//Solve on paper first
//Overflooooooow
//Reverse Thinking
//If there's an equation, transform it into an easy one
//READ ALL PROBLEMS
//Verify Your thought before Coding
Copy