#include <bits/stdc++.h>
using namespace std;
const int N = 8e6 + 9;
const int mod = 1e9 + 7;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
string s;
cin >> s;
int n = s.size();
int pre[4][n + 1];
memset(pre, 0 , sizeof pre);
for(int i = 0; i < n; i++){
for(int j = 0; j < 4; j++){
pre[j][i + 1] = pre[j][i];
}
if(s[i] == '1') pre[(i + 1) % 4][i + 1]++;
}
int q;
cin >> q;
while(q--){
int l , r;
cin >> l >> r;
int ans = 0;
if(s[r - 1] == '1') ans++;
//cout << pre[1][r - 1] << "\n";
if(r - 1 >= l)ans += (pre[(r - 1) % 4][r - 1] - pre[(r - 1) % 4][l - 1]) * 2;
ans %= 10;
if(r - 2 >= l)ans += (pre[(r - 2) % 4][r - 1] - pre[(r - 2) % 4][l - 1]) * 4;
ans %= 10;
if(r - 3 >= l)ans += (pre[(r - 3) % 4][r - 1] - pre[(r - 3) % 4][l - 1]) * 8;
ans %= 10;
if(r - 4 >= l)ans += (pre[(r - 4) % 4][r - 1] - pre[(r - 4) % 4][l - 1]) * 6;
ans %= 10;
cout << ans << "\n";
}
return 0;
}
Copy