//Esraa_Taha
//إن مررت من هنا فأدع لي
#include <bits/stdc++.h>
using namespace std;
#define zrebeooo ios_base::sync_with_stdio(false);cin.tie(NULL);
#define zrebeooo2 cin.tie(0); cin.sync_with_stdio(0);
#define ll long long
#define sz(x) (int)x.size()
#define pb push_back
#define pf push_front
#define po pop_back
#define pi acos(-1) //radian
#define eu(s) s.erase(unique(be(s)),s.end())
#define fs(n) fixed<<setprecision(n)
#define vi vector<int>
#define vl vector<ll>
#define el '\n'
#define S second
#define F first
#define be(s) (s).begin() , (s).end()
#define clr(x , v) memset(x , v , sizeof(x))
#define sz2(a) sizeof((a))/sizeof((a[0]))
#define ln(i,k,n) for (int i=n ; i>=k ; i--)
#define l(i,k,n) for (int i=k ; i<n ; i++)
#define loop(it , s) for (it= s.begin() ; it != s.end() ; it++)
#define loopr(it , s) for (it= s.rbegin() ; it != s.rend() ; it++)
#define M 1000000007
#define test int t; cin>>t; while(t--)
//======================================================
ll gcd(ll a, ll b) //O(log(min(a,b)))
{
return (b ? gcd (b, a%b) : a);
}
ll lcm(ll a, ll b)
{
return (a / gcd(a, b))*b;
}
ll egcd(ll a, ll b, ll& x,ll& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll d = egcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
//=======================================================
void input()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
#endif
}
//======================================================
/*int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1}; //j
int dy[] = { 0, 1, -1, 0, -1, 1, 1, -1}; //i*/
//======================================================
ll mulmod(ll a , ll b , ll mod) {
if(a>b) return mulmod(b,a,mod);
ll x = 0, y = a % mod;
while (b) {
if (b&1) {
x = (x%mod + y%mod)%mod;
}
y = (y <<= 1)%mod;
b >>= 1;
}
return x%mod;
}
//======================================================
ll power(ll b , ll p , ll m){
ll an=1;
while(p){
if(p&1){
an*=b;
an%=m;
}
b*=b;
b%=m;
p >>= 1;
}
return an%m;
}
//======================================================
/*vector<bool> is_prime;
vl s;
void sieve(ll n) {
is_prime.assign(n+1, true);
is_prime[0] = is_prime[1] = 0;
for(ll i=4 ; i<=n ; i+=2) is_prime[i]=0;
for (ll i = 3 ; i*i <= n ; i+=2){
if (is_prime[i])
for (ll j = i * i; j <= n; j += i) is_prime[j] = 0;
}
l(i , 2 , n+1) if(is_prime[i]) s.pb(i);
}*/
//======================================================
void linearsieve(int n){
vi pr;
vector<bool> lp(n+1 , 0);
for (int i=2; i <= n; ++i) {
if (lp[i] == 0) {
pr.push_back(i);
}
for (int j=0; j < (int)pr.size() && pr[j] <= lp[i] && i*pr[j] <= n; ++j) {
lp[i * pr[j]] = 1;
}
}
}
//======================================================
vector<ll> primedivs(ll N){
vector<ll> primeDivs[N];
for (ll i = 2; i <= N; i++) {
if(sz(primeDivs[i])) continue;
for (ll j = i; j <= N; j += i)
primeDivs[j].pb(i);
}
return primeDivs[N];
}
//======================================================
int a[4][200001]={};
int main ()
{
zrebeooo zrebeooo2
//input();
//مهما الدنيا إتنيلت ضلمت لازم يبقى عندك زفت أمل و تعرف إن في نور في أخر أم النفق//
//THINK TWICE .. CODE ONCE//
//ACPC//
//فاكس؟ فاكس//
string s;
cin>>s;
l(j , 0 , sz(s)-1){
if(s[j]=='1'){
a[(sz(s)-j-2)%4][j]=1;
}
}
l(i , 0 , 4)
l(j , 0 , sz(s))
if(j) a[i][j]+=a[i][j-1];
int q;
cin>>q;
while(q--){
int l,r,k=0;
cin>>l>>r;
l--; r--;
int ans=(s[r]=='1');
r--;
while(r>=l && k<4){
int y = a[(sz(s)-r-2)%4][r];
if(l) y-=a[(sz(s)-r-2)%4][l-1];
if(!k) y*=2;
else if(k==1) y*=4;
else if(k==2) y*=8;
else y*=6;
ans += y;
ans%=10;
r--; k++;
}
cout<<ans<<el;
}
return 0;
}
Copy