#include <iostream>
using namespace std;
int main() {
int n,k;
cin>>n;
int a[n+1];
long long pr[n+2]={0,};
for(int i=1; i<=n; i++)
cin>>a[i];
cin>>k;
for(int i=1; i<=n; i++)
if(a[i]==0) pr[i]=pr[i-1]+1;
else pr[i]=pr[i-1];
for(int i=0; i<k; i++){
int x1,x2,y1,y2;
cin>>x1>>x2>>y1>>y2;
cout<<pr[y1]-pr[x1-1]<<" "<<pr[y2]-pr[x2-1];
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIHsKCWludCBuLGs7CgljaW4+Pm47CglpbnQgYVtuKzFdOwoJbG9uZyBsb25nIHByW24rMl09ezAsfTsKCWZvcihpbnQgaT0xOyBpPD1uOyBpKyspCgkJY2luPj5hW2ldOwoJY2luPj5rOwoJZm9yKGludCBpPTE7IGk8PW47IGkrKykKCQlpZihhW2ldPT0wKSBwcltpXT1wcltpLTFdKzE7CgkJZWxzZSBwcltpXT1wcltpLTFdOwoJZm9yKGludCBpPTA7IGk8azsgaSsrKXsKCQlpbnQgeDEseDIseTEseTI7CgkJY2luPj54MT4+eDI+PnkxPj55MjsKCWNvdXQ8PHByW3kxXS1wclt4MS0xXTw8IiAiPDxwclt5Ml0tcHJbeDItMV07Cgl9Cn0=