#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());
const int N = 5e5;
string s;
int cs[N],power[N];
int main(){
cin >> s;
power[0] = 1;
for(int i = 1;i <= s.size();i++)cs[i] = (cs[i - 1]*2LL + s[i - 1] - '0')%10,power[i] = power[i - 1]*2LL%10;
int n;
scanf("%d",&n);
while(n--){
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",((cs[r] - cs[l - 1]*1LL*power[r - l + 1])%10 + 10)%10);
}
}
Copy