#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
typedef pair<int, int>pr;
#define all(i)     i.begin() , i.end()
#define ft     first
#define sn     second
#define pb push_back

#define en "\n"
#define dbg cout<<"rony\n"

#define MAXN 30010
#define inf 1e6+5
const ll mod = 1e9 + 7;

int n;
int a[MAXN];

struct segment_tree
{
    struct NODE {
        int st , EN;
        vector<int>v;

        void init(int L, int R) {
            st = L, EN = R;
            if (L == R) v.pb(a[L]);
        }
    } g[3 * MAXN];

    void merge(vector<int>&A, vector<int>&B, vector<int>&C)
    {
        int i = 0, j = 0;
        while (i < B.size() && j < C.size())
        {
            if (B[i] < C[j]) {
                A.pb(B[i]); i++;
            }
            else {
                A.pb(C[j]); j++;
            }
        }

        while (i < B.size()) {A.pb(B[i]); i++;}
        while (j < C.size()) {A.pb(C[j]); j++;}
    }

    void fill_CN(NODE &CN, NODE &LN, NODE &RN) // fill_current_node
    {
        merge(CN.v, LN.v, RN.v);
    }

    void build(int CN, int L, int R)
    {
        g[CN].init(L, R);

        if (L == R ) return;
        int mid = (L + R) >> 1;

        build(CN * 2, L, mid);
        build(CN * 2 + 1, mid + 1, R);

        fill_CN (g[CN], g[CN * 2] , g[CN * 2 + 1]);
    }

    int query(int CN, int L, int R, int val)
    {
        int x = g[CN].st;
        int y = g[CN].EN;
        if (y < L || x > R) return 0;

        if (L <= x && R >= y ) {
            int ub = upper_bound(all(g[CN].v), val) - g[CN].v.begin();
            return (int)g[CN].v.size() - ub;
        }

        int LN = CN << 1;

        int ans = query(LN, L, R, val);
        ans += query(LN | 1, L, R, val);
        return ans;
    }

} s_tree;
void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    s_tree.build(1, 1, n);

    int q; cin >> q;
    while (q--)
    {
        int l, r, x;
        cin >> l >> r >> x;
        cout << s_tree.query(1, l, r, x) << en;
    }

}
int main()
{
    IOS;
    ll t;
    t = 1;

    // cin >> t;

    int c = 0;
    while ( t-- )
    {
        // cout<<"Case "<<++c<<": ";
        solve();
    }
    return 0;
}