#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define sz(x) (int)x.size()
void setFile() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
}
const int N = 2e5 + 10;
string s;
int n, q, sum[N], p[] = {2, 4, 8, 6};
int main() {
setFile();
cin >> s;
n = sz(s);
for (int i = 0; i < n; i++) {
sum[i] = s[i] == '1';
if (i >= 4)
sum[i] += sum[i - 4];
if (sum[i] >= 10)
sum[i] -= 10;
}
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
l--;
r--;
int ans = s[r--] == '1';
for (int i = 0, j; r >= l && i < 4; i++, r--) {
ans += sum[r] * p[i];
j = r - (r - l) / 4 * 4 - 4;
if (j >= 0)
ans -= sum[j] * p[i];
}
cout << (ans % 10 + 10) % 10 << endl;
}
}
Copy