//never give up.... just cry when you have to do 🌵🙂
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) v.size()
#define mem(dp) memset(dp, 0 , sizeof dp)
long double pi = acos(-1);
void FILe() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); }
void FAST() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); }
ll fpow(ll n, ll x, int mod=1e1)
{
if (x == 0) return 1 % mod;
else if (x == 1) return n % mod;
ll ans = fpow(n, x / 2, mod);
ans = ans * ans % mod;
if (x & 1) ans = ans * n % mod;
return ans;
}
string s;
ll a[200005];
int main()
{
//freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
FAST();
cin >> s;
int n = s.length();
a[n] = 0;
a[0] = (s[0] == '0') ? 0 : 1;
for (int i = 1;i <n;i++)
{
if (s[i] == '1') a[i] = a[i - 1] * 2 + 1;
else a[i] = a[i-1]*2;
a[i] %= 10;
}
/*for (int i = 0;i < n;i++)
{
cout << a[i] << " ";
}cout << "\n";*/
ll q, l, r;
cin >> q;
while (q--)
{
cin >> l >> r;
l--,r--;
if (l == 0)cout << a[r] << "\n";
else
{
ll ans = a[r] - (a[l - 1] * fpow(2, r - (l - 1)));
ans %= 10;
while (ans < 0)
ans += 10;
cout << ans << "\n";
}
}
return 0;
}
Copy