#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <algorithm>

#define MAXN 50000

using namespace std;

int n,q,x[MAXN+1],l,r,a,b,d,ind1,ind2,ret;

int binarnaa(int donja,int gornja,int query)
{
    int pivot;
    while(gornja>donja)
    {
              pivot=(gornja+donja)/2;
              if(pivot<query) donja=pivot+1;
              else if(pivot>query) gornja=pivot-1;
              else if(pivot==query) gornja=pivot;   
    }
    return gornja;
}

int binarnab(int donja,int gornja,int query)
{
    int pivot;
    while(gornja>donja)
    {
              pivot=(gornja+donja)/2;
              if(gornja-donja==1) pivot++;
              if(pivot<query) donja=pivot+1;
              else if(pivot>query) gornja=pivot-1;
              else if(pivot==query) donja=pivot;           
    }
    return gornja;
}

int main(int argc, char *argv[])
{
    freopen("pijaca.in","r",stdin);
    freopen("pijaca.out","w",stdout);
    
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
            scanf("%d",&x[i]);
    sort(x,x+n);
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
            scanf("%d %d %d %d %d",&d,&l,&r,&a,&b);
            ind1=binarnaa(l,r,a);
            ind2=binarnab(l,r,b);
            ret=ind2-ind1+1;
            printf("%d\n",ret);
    }
   // system("PAUSE");
    return 0;
}
