#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(s) (int)(s.size())
const ll N = 2e5+3;
const ll OO = 1e18;
const auto EPS = 1e-6;
using namespace std;
int DX[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int DY[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dx[] = { 1,0,-1,0 } ,dy[] = { 0,1,0,-1 };
ll fpow(ll x, ll n)
{
ll res = 1;
while(n)
{
if(n&1)
res = ((res%10) * (x%10))%10;
n >>= 1;
x = ((x%10) * (x%10))%10;
}
return res;
}
int pre[200006];
void testCase()
{
string s;
cin >> s;
int n = s.length();
for(int i=1;i<=s.length();i++)
{
pre[i] = (pre[i-1]*2 + (s[i-1] == '1'))%10;
}
int q;
cin >> q;
while(q--)
{
int l, r;
cin >> l >> r;
int x = pre[l-1]* fpow(2,r-l);
x%=10;
cout << (pre[r] - x) << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1; //cin >> t;
for(int tc = 1;tc<=t;tc++)
{
// cout << "Case #" << tc << ": ";
testCase();
}
return 0;
}
Copy