#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N+5, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N+5?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.sv_num = res.sv_val = -666;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    cur=0;
    memset(cnt, 0, sizeof(cnt));
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                if( pre[j].sv_num != -666 ) sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val;
                cur+=pre[j].curadd;
            }
        }

        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[20 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        //this->sz = 0;
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[20 * N], *Seg::pmem = mem;
int n,Q,v,Ql,Qr,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Ql, &Qr, &k);
        --Ql;
        k = (Qr - Ql) / k;
        ans = N+10;
        Query(1, n, ver[Ql], ver[Qr]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N+5, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N+5?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    cur=0;
    memset(cnt, 0, sizeof(cnt));
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    //freopen("in","r",stdin);
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[21 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[21 * N], *Seg::pmem = mem;
int n,Q,v,Qli,Qri,k,ans;
Seg *ver[N+5];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Qli, &Qri, &k);
        --Qli;
        k = (Qri - Qli) / k;
        ans = N+10;
        Query(1, n, ver[Qli], ver[Qri]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N+5, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N+5?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.sv_num = res.sv_val = -666;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
vector<int> mns;
void sol(Query &ip){
    cur=0;
    for(int i=0;i<SZ(mns);++i) cnt[ mns[i] ]--;
    mns.clear();
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
        mns.push_back(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                if( pre[j].sv_num != -666 ) sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val;
                cur+=pre[j].curadd;
            }
        }

        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[30 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        //this->sz = 0;
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[20 * N], *Seg::pmem = mem;
int n,Q,v,Ql,Qr,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Ql, &Qr, &k);
        --Ql;
        k = (Qr - Ql) / k;
        ans = N+10;
        Query(1, n, ver[Ql], ver[Qr]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[30 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        this->sz = 0;
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[30 * N], *Seg::pmem = mem;
int n,Q,v,Ql,Qr,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Ql, &Qr, &k);
        --Ql;
        k = (Qr - Ql) / k;
        ans = N+10;
        Query(1, n, ver[Ql], ver[Qr]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[10], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    cur=0;
    memset(cnt, 0, sizeof(cnt));
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR, bnL, bnR;
    for(int i=0; i<SZ(Q); ++i){
        if(!i||Q[i].bid>Q[i-1].bid){
            nL = nbidL[Q[i].bid];
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
            nL = bnL, nR = bnR;
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
        bnL = nL, bnR = nR;
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[10], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<6){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    cur=0;
    memset(cnt, 0, sizeof(cnt));
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR, bnL, bnR;
    for(int i=0; i<SZ(Q); ++i){
        if(!i||Q[i].bid>Q[i-1].bid){
            nL = nbidL[Q[i].bid];
            nR = nL-1;
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
            nL = bnL, nR = bnR;
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
        bnL = nL, bnR = nR;
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    cur=0;
    memset(cnt, 0, sizeof(cnt));
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n+0.1);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[10], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    cur=0;
    memset(cnt, 0, sizeof(cnt));
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
            pre_cur = 0;
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[N+5];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){
        res.sv_val = sv[ res.sv_num = fd ];
        sv[fd] = x;
    } else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.curadd = -1;
            res.sv_num = cur;
            res.sv_val = sv[cur];
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    cur=0;
    memset(cnt, 0, sizeof(cnt));
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        if(!i||Q[i].bid>Q[i-1].bid){
            nL = nbidL[Q[i].bid];
            nR = nL-1;
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N+5, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N+5?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.sv_num = res.sv_val = -666;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
vector<int> mns;
void sol(Query &ip){
    cur=0;
    mns.clear();
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
        mns.push_back(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    for(int i=0;i<SZ(mns);++i) cnt[ mns[i] ]--;
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                if( pre[j].sv_num != -666 ) sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val;
                cur+=pre[j].curadd;
            }
        }

        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[30 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR){
        this->sz = 0;
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[30 * N], *Seg::pmem = mem;
int n,Q,v,Ql,Qr,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Ql, &Qr, &k);
        --Ql;
        k = (Qr - Ql) / k;
        ans = N+10;
        Query(1, n, ver[Ql], ver[Qr]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[22 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[22 * N], *Seg::pmem = mem;
int n,Q,v,Qli,Qri,k,ans;
Seg *ver[N+5];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Qli, &Qri, &k);
        --Qli;
        k = (Qri - Qli) / k;
        ans = N+10;
        Query(1, n, ver[Qli], ver[Qri]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[4], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    cur=0;
    memset(cnt, 0, sizeof(cnt));
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR;
    for(int i=0; i<SZ(Q); ++i){
        nL = nbidL[Q[i].bid];
        if(!i||Q[i].bid>Q[i-1].bid){
            nR = nL-1;
            cur=0;
            memset(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[25 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        //this->sz = 0;
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[20 * N], *Seg::pmem = mem;
int n,Q,v,Ql,Qr,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Ql, &Qr, &k);
        --Ql;
        k = (Qr - Ql) / k;
        ans = N+10;
        Query(1, n, ver[Ql], ver[Qr]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
using namespace std;
struct Seg{
    static Seg mem[30 * N], *pmem;
    Seg *Ls, *Rs;
    int sz;
    Seg(){};
    Seg(int nL, int nR) : sz(0){
        if(nL==nR) return;
        int mid = (nL+nR)>>1;
        Ls = new (pmem++) Seg(nL, mid);
        Rs = new (pmem++) Seg(mid+1, nR);
    }
    Seg* ins(int nL, int nR, int v){
        Seg *t = new (pmem++) Seg (*this);
        t->sz++;
        if(nL!=nR){
            int mid = (nL+nR)>>1;
            if( v <= mid ){
                t->Ls = t->Ls->ins(nL, mid, v);
            } else {
                t->Rs = t->Rs->ins(mid+1, nR, v);
            }
        }
        return t;
    }
}Seg::mem[30 * N], *Seg::pmem = mem;
int n,Q,v,Qli,Qri,k,ans;
Seg *ver[N+10];
void Query(int nL, int nR, Seg *Ql, Seg *Qr){
    if(nL==nR){
        if( (Qr->sz - Ql->sz)>k ){
            ans = min(ans, nL);
        }
    } else {
        int mid = (nL+nR)>>1;
        if( Qr->Ls->sz - Ql->Ls->sz > k ) Query(nL, mid, Ql->Ls, Qr->Ls);
        if( Qr->Rs->sz - Ql->Rs->sz > k ) Query(mid+1, nR, Ql->Rs, Qr->Rs);
    }
    return ;
}
int main(void){
    scanf("%d%d",&n,&Q);
    ver[0] = new (Seg::pmem++) Seg(1,n);
    for(int i=1;i<=n;++i){
        scanf("%d",&v);
        ver[i] = ver[i-1] -> ins(1, n, v) ;
    }
    while(Q--){
        scanf("%d%d%d",&Qli, &Qri, &k);
        --Qli;
        k = (Qri - Qli) / k;
        ans = N+10;
        Query(1, n, ver[Qli], ver[Qri]);
        printf("%d\n",ans==N+10?-1:ans);
    }
}


#include<bits/stdc++.h>
#define N 300000
#define SZ(x) (int)(x.size())
#define F first
#define S second
using namespace std;
int arr[N+5], ans[N+5], nbidL[1000], cnt[N+5];
struct Query{
    int L, R, id, k, bid;
    bool operator < (const Query &rhs) const {
        return bid < rhs.bid || ( bid==rhs.bid && R < rhs.R ) ;
    }
};
vector<Query> Q;
struct pre_sit{
    int cnt_num, cnt_val, sv_num, sv_val, curadd;
}pre[1000];
int pre_cur;
int sv[10], cur;
int get_Ans(Query &x){
    int mn_id = N, num = (x.R - x.L + 1) / x.k ;
    for(int i=0;i<cur;++i){
        if( cnt[sv[i]] > num ){
            mn_id = min(mn_id, sv[i]);
        }
    }
    return mn_id==N?-1:mn_id ;
}
pre_sit Add(int x){
    pre_sit res;
    res.curadd = 0;
    int fd = -1;
    for(int i=0;i<cur;++i){
        if(sv[i]==x){
            fd = i;
        }
    }
    res.cnt_num = x, res.cnt_val = cnt[x];
    ++cnt[x];
    if(fd>=0){;}
    else {
        int mn_pl = 0;
        for(int i=1;i<cur;++i){
            if( cnt[sv[i]] < cnt[sv[mn_pl]] ){
                mn_pl = i;
            }
        }
        if(cur<4){
            res.sv_num = cur;
            res.sv_val = sv[cur];
            res.curadd = -1;
            sv[cur++] = x;
        }
        else if( cnt[x] > cnt[sv[mn_pl]] ){
            res.sv_num = mn_pl;
            res.sv_val = sv[mn_pl];
            sv[mn_pl] = x;
        }
    }
    return res;
}
void sol(Query &ip){
    for(int i=ip.L; i<=ip.R; ++i){
        Add(arr[i]);
    }
    ans[ip.id] = get_Ans(ip);
    cur=0;
    memset(cnt, 0, sizeof(cnt));
}
void Mo(){
    sort(Q.begin(), Q.end());
    int nL, nR, bnL, bnR;
    for(int i=0; i<SZ(Q); ++i){
        if(!i||Q[i].bid>Q[i-1].bid){
            nL = nbidL[Q[i].bid];
            nR = nL-1;
            cur=0;
            memest(cnt, 0, sizeof(cnt));
        } else {
            for(int j=pre_cur-1;j>=0;--j){
                cnt[ pre[j].cnt_num ] = pre[j].cnt_val ;
                 sv[ pre[j].sv_num  ] = pre[j].sv_val  ;
                cur+=pre[j].curadd;
            }
            nL = bnL, nR = bnR;
        }
        while(nR<Q[i].R) Add( arr[++nR] );
        pre_cur = 0;
        while(nL>Q[i].L) pre [ pre_cur++ ] = Add( arr[--nL] );
        ans[Q[i].id] = get_Ans(Q[i]);
        bnL = nL, bnR = nR;
    }
}

int main(void){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;++i) scanf("%d",arr+i);
    int sqrn = sqrt(n);
    Query ip;
    for(int i=0;i<q;++i){
        scanf("%d%d%d", &ip.L, &ip.R, &ip.k);
        ip.L--, ip.R--;
        ip.id = i;
        if(ip.L / sqrn==ip.R / sqrn){
            sol(ip);
        } else {
            ip.bid = ip.L / sqrn;
            nbidL[ip.bid] = max(nbidL[ip.bid], ip.L);
            Q.push_back(ip);
        }
    }
    Mo();
    for(int i=0;i<q;++i) printf("%d\n",ans[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	double ans=0.0,x,y;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y;
	}
	ans/=n;
	printf("%.3lf\n",ans+5.0);
}


#include<bits/stdc++.h>
using namespace std;
int n,i;
double x,y,s;
int main()
{
  cin>>n;
  for(i=1;i<=n;i++)
   {
    cin>>x>>y;
    s+=y;
   }
  s/=n;
  printf("%.3lf\n",s+5);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<vector>
using namespace std;
int main()
{
    double n,in,sum1=0.00,sum2=5.00;
    scanf("%lf",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%*lf %lf",&in);
        sum1 += in;
    }
    sum2+=sum1/n;
    printf("%.3lf",sum2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
double n,x,y,sum;
int main()//仔细看
{
    scanf("%lf",&n);//输入N
    for( int i=1;i<=n;i++)scanf("%lf%lf",x,y),sum+=y;//X直接忽略
    printf("%.3lf",sum/n+4);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	double x,y;
  double sum=0;
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&x,&y);
		sum+=y;
	}
	sum=sum/n;
	printf("%.3lf\n",sum+5);
	return 0;
}


#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int FFF=6666;

int n;
double x[FFF],y[FFF],ans;

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<n;++i)
    {
        cin>>x[i]>>y[i];
        ans+=y[i];
    }
    ans/=n;
    ans+=5;
    printf("%.3lf",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
 double x,y,s=0;
 cin>>n;
 for(int i=0;i<n;i++)
    {cin>>x>>y;
     s+=y;}
 printf("%.3lf",s/n+5);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	double n,x,y,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y;
	}
	ans/=n;
	printf("%0.3lf",ans+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    double x,y,s=5;
    for(int i=0;i<a;i++)
    {
        cin>>x>>y;
        s+=y;
    }
    s/=a;
    printf("%.3lf\n",sum+5);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct kkksc03
{
	float x,y;
 };
int main()
{
	int n;
	float y = 0;
	kkksc03 taijuanle[1001];
	cin >> n;
	for (int i = 1;i <= n;i ++)
	{
		cin >> taijuanle[i].x >> taijuanle[i].y;
		y += taijuanle[i].y;
	}
	cout << fixed << setprecision(3) << y / n + 5;
}


#include<bits/stdc++.h>
#define ld long double
using namespace std;
int main()
{
    int n;
    cin>>n;
    ld sum=0;
    for(int i=1;i<=n;i++)
    {
    	ld x,y;
    	cin>>x>>y;
    	sum+=y;
	}
	sum/=n;
	sum++;
	sum++;
	sum++;
	sum++;
	sum++;
	cout<<fixed<<setprecision(3)<<endl;
	return 0;
}


#include<bits/stdc++.h>
double x,n,y,sum1 = 0.00,sum2 = 5.00;
using namespace std;
int main()
{
    cin>>n;
    for(int i = 0;i < n;i++)
    {
        cin>>x>>y;
        sum1 +=y;
    }
    sum2 += sum1 / n;
    printf("%.3lf",sum2);
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
double x[1001],y[1001],ans;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i];
		ans+=y[i];
	}
	ans/=n;
	ans+=5;
	printf("%0.3f",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	double a=0;
	for(int i=0;i<n;i++){
		double x,y;
		cin>>x>>y;
		a+=y;
	}
	a/=n;
	cout<<a+5;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef double db;
int n;
db sum,k;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
//		getchar();
		db x;
		cin>>k>>x;
		sum+=x;
	}
	sum/=n;
	printf("%.3lf\n",sum+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double a,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		cin>>a;
		ans+=a;
	}
	cout<<ans/n+5;
}


#include<stdio.h>
int n,t;double x,y,sum;
int main()
{
	scanf("%d",&n);
	for(;t<n;t++)
	{
    	scanf("%lf%lf",&x,&y);
    	sum+=y/n;
	}
	printf("%.3lf",sum+5);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int n;
double x[1020],y[1020];
double ans=5.000;
int main()
{
	double he=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>y[i];
		y[i]/=n;
		he+=y[i];
	}
	ans+=he;
	printf("%.3lf",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
double n,ans,x,y;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		ans+=y;
	}
	ans/=n;
	cout<<fixed<<setprecision(3)<<ans+5;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

int main()
{
	int n;
	double x,y,ans=0;
    cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans=(ans*(i-1)+y)/i;
	}
	ans+=5;
	printf("%.3lf",ans);
    return 0;
}


#include<cstdio>
using namespace std;
int main()
{
	int n=0,count=0;
	float sumy=0;
	while(1)
	{

		if(!n)
		{
			scanf("%d",&n);
		}
		else if(count==n)
		{
			printf("%.3f",5+sumy/n);
			return 0;
		}
		else
		{
			float x;
			scanf("%*f %f",&x);
			sumy+=x;
			count++;
		}
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
double x;
double y;
int main(){
  int n;
  cin>>n;
  double sum;
  for(int i=1;i<=n;++i){
    cin>>x>>y;
    sum=sum+y;
  }
  sum=sum/5.0;
  sum=sum+5;
  printf("%.3lf",sum);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
double x,y,h=0; int n,i;
int main()
{
	scanf("%d",&n); h=5*n;
	for(i=1;i<=n;++i)
	scanf("%lf%lf",&x,&y),h+=y;
	printf("%.5lf",h/n);
	return 0;
}


#include<iostream>
using namespace std;
double n,a,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%*lf %lf",&a);
        ans+=a;
    }
    printf("%.3lf",5.000+ans/n);
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    double n,in,sum1 = 0.00,sum2 = 5.00;
    scanf("%lf",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%*lf %lf",&in);
        sum1+=in;
    }
    sum2+=sum1/n;
    printf("%.3lf\n",sum2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
double n,y,w,s;
int main()
{
    cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>y>>w;
		s+=w;
	}
	printf("%.3lf",s/n+5);

	return 0;
}


#include<cstdio>
using namespace std;
int n=0,count=0;
float sumy=0;
int main(){
    if(!n) { scanf("%d",&n); main();}
    else if(count==n) { printf("%.3f",5+sumy/n); return 0; }
    else{
        float x;scanf("%*f %f",&x);
        sumy+=x;count++;
        main();
    }
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    double sum = 0.0000,t;
    for(int i = 0;i < n;i++)
    {
        cin >> t;
        sum += t;
    }
    cout << 5 + sum / n;
    return 0;
}


#include<cstdio>
#include<iostream>
using namespace std;
int n;
double x,y,sum=0;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		sum+=y;
	}
	printf("%0.3lf",5+sum/(double)n);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	short f=1;x=0;char c=getchar();
	while(!isdigit(c)){ if(c=='-')f=-1;c=getchar(); }
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	x*=f;
}
int main(){
	int n;double x,y,ans;
	read(n);
	for(int i=1;i<=n;i++)cin>>x>>y,ans+=y;
	ans=ans/(double)n+5.0;
	cout<<fixed<<setprecision(3)<<ans<<endl;
	return 0;
}


#include <cstdio>

using namespace std;

int n;
float x,y,sum;

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%f%f",&x,&y);
        sum+=y;
    }
    printf("%.3f\n",5+sum/n);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n;
double x,y,ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y;
	}
	printf("%.3lf",ans/n+5);
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n;double sum=0.0,a,b;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(n);
	for(int i=1;i<=n;i++){
		cin>>a>>b;sum+=1.0*b;
	}
	printf("%.3lf\n",5+sum/n);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
double ans,y;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%*lf %lf",&y);
		ans+=y;
	}
	printf("%.3lf",ans/n+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	double m,k,l=0;
	long long n,i;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>m>>k;
		l+=k;
	}
	cout<<fixed<<setprecision(3)<<l/n+5;
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;

int main(){
	double x,y,sum=0; int n; scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%lf%lf",&x,&y),sum+=y;
	printf("%.3lf",sum/(double)(n)+5.000);
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

int main()
{
	int n;
	double x,y,ans=0;
   	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans=(ans*(i-1)+y)/i;
	}
	ans+=5;
	printf("%.3lf",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
double x,y,sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		sum+=y;
	}
	sum/=n;
	printf("%.3lf",sum+5);
	return 0;
}


#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <sstream>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <iosfwd>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <cwchar>
#include <cwctype>
#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
using namespace std;
double n,in,sum1=0.00,sum2=5.00;
#define qwq scanf("%*lf %lf",&in);
#define wq printf("%.3lf",sum2);
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        qwq
        sum1+=in;
    }
    sum2+=sum1/n;
    wq
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	double x,y,sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		sum+=y;
	}
	sum=sum/n;
	printf("%.3lf",sum+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
double x,y,ans;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>x>>y;
        ans=(ans*(i-1)+y)/i;
    }
    ans+=5;
    printf("%.3lf",ans);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    long double n,y,s=0;
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>y>>y;
        s+=y;
    }
    s/=n;
    printf("%.3lf\n",s+5);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
double sum,n;
int main(){
	scanf("%lf",&n);
	for(int i=1;i<=n;i++){
		double x,y;
		scanf("%lf%lf",&x,&y);
		sum+=y;
	}
	printf("%.3lf",sum/n+5);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    double x,y,s=0;
    for(int i=0;i<a;i++)
    {
        cin>>x>>y;
        s+=y;
    }
    s/=a;
    printf("%.3lf\n",s+5);
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n;
double x,y,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y;
	}
	printf("%.3f",ans/n+5);
	return 0;
}


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

int main()
{  int n;
   double x,y,ans;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
          	cin>>x>>y;
			  ans+=y;
  }
   printf("%.3lf",ans/n+5);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	double x[1001],y[1001],n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	  {
	  	cin>>x[i]>>y[i];
	  	ans+=y[i];
	  }
	printf("%0.3f",ans/n+5);
}


#include<bits/stdc++.h>
using namespace std;
int n;
double x,y,sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		sum+=y;
	}
	printf("%.3lf\n",sum/n+5);
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n;

int main()
{
	float ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		float x,y;
		scanf("%f%f",&x,&y);
		ans+=y;
	}
	ans=ans/(n*1.0)+5;
	printf("%.5f\n",ans);
	return 0;
}


#include<stdio.h>
int main()
{
    double n,in,sum1 = 0.00,sum2 = 5.00;
    scanf("%lf",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%*lf %lf",&in);
        sum1 += in;
    }
    sum2 += sum1 / n;
    printf("%.3lf",sum2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
double n,a,b,sum;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		{
			cin >> a >> b;
			sum += b;
		}
	sum /= n;
	sum += 5;
	cout << fixed << setprecision(3) << sum << endl;
	return 0;
 }


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
double n,x,y,sum;
int nain(){
    scanf("%lf",&n);
    for(reg int i=1;i<=n;i++){
	scanf("%lf%lf",x,y);
	sum+=y;
	}
    printf("%.3lf",sum/n+4);
    return 0;
}


#include <cstdio>
using namespace std;
int t;
int main(){
    scanf ("%d",&t);
    double ans=0.00;
    for (int i=0;i<t;i++){
        double x,y;
        scanf ("%.2f%.2f",&x,&y);
        ans+=y;
    }
    ans*=1.000;
    ans/=t;
    ans+=5;
    printf ("%.3f",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int b;
	cin>>b;
	double a[b],c[b],e=0,d=0;
	for(int i=0 ; i<b ; i++)
	{
		cin>>a[i]>>c[i];
	}
	for(int i=0 ; i<b ; i++)
	{
		e=e+c[i];
	}
	e=e/b;
	int x=e*100;
	d=x/100;
	cout<<fixed<<setprecision(3)<<d+5;
	return 0;
}


#include<iostream>
#include<cstdio>
#define maxd 1000000007
using namespace std;
double ans=0.0;
double x,y;
int n;
int main(){
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x>>y;
    ans+=y;
  }
  printf("%0.3lf",ans/n+5);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<ctime>
#include<set>
#include<cctype>
#define INF 0x7fffffff
#define ll long long
#define IL inline
#define R register
using namespace std;
/*我啊，只是想证明。这样的我，就算是这样的我，
也有能够靠自己的双手争取到的东西。 ——《Fate/Zero》*/
/*我爱slay
更爱刷题qwqwqwqwqwq，不颓*/
int n;
float x,y,sum;

int main()
{
    //	freopen("qwqw.in","r",stdin);
    //	freopen("qwqw.out","w",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        sum+=y;
    }
    // cout<<sum/n+5<<endl;
    printf("%.3lf",sum/n+5);
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
double n,x,y,sum;
int main()
{
	scanf("%lf",&n);
	for(reg int i=1;i<=n;i++)scanf("%lf%lf",x,y),sum+=y;
	printf("%.3lf",sum/n+5);
}


#include<bits/stdc++.h>
using namespace std;
int n,i;
double x,y,s=0;
int main()
{
   	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>x>>y;
		s=(s*(i-1)+y)/i;
	}
	s+=5;
	printf("%.3lf",s);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MOD 192837465
#define init inline int
int main(){
	ios::sync_with_stdio(0);
	int n;
	double y;
	cin>>n;
	double a[n],b[n];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		y+=b[i];
	}
	y/=double(n);
	cout<<y+5.0;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
double ans, x, y;
main ()
{
    cin >> n;
    for (int i = 0; i < n ; i++)
        {cin >> x >> y; ans += y;}
    ans /= n;
    cout << ans + 5;
}


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

int main()
{
	int x; cin >> x;
	double ans = 0;
	for (int i = 0; i < x; ++i)
	{
		double a, b;
		cin >> a >> b;
		ans += b;
	}
	cout << ans/x+5 << '\n';
}


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128

double sum = 0;
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    double x; cin >> x >> x;
    sum += x;
  }
  printf("%.3lf\n", sum / n + 5.0);
  return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	double a, b, sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		sum += b;
	}
	sum /= n;
	sum += 5;
	printf("%.3lf", sum);
	return 0;
}
//2


#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
double n,x,y,sum;
int main()//仔细看
{
    scanf("%lf",&n);
    for(reg int i=1;i<=n;i++)scanf("%lf%lf",x,y),sum+=y;
    printf("%.3lf",sum/n+5);
}


#include<bits/stdc++.h>
using namespace std;
double n,x,y,sum;
int main()
{
    scanf("%lf",&n);
    for(int i=1;i<=n;i++)scanf("%lf%lf",&x,&y),sum+=y;
    printf("%.3lf",sum/n+5);
}


#include<cstdio>
int n,t;double x,y,s;
int main()
{
for (scanf("%d",&n),t=n;n--;) scanf("%lf%lf",&x,&y),s+=y;
printf("%.9lf",5+s/t);
}


#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	double sum=0;
	for(int i=1;i<=n;i++){
		double x,y;
		cin>>x>>y;
		sum+=y;
	}
	sum=sum/(double)n;
	sum+=5;
	printf("%.3lf\n",sum);
	return 0;
}


#include<cstdio>
double x,y,sum;
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf%lf",&x,&y);
		sum+=y;
	}
	printf("%.3lf",sum/n+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    double x,y,ans = 0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>x>>y,ans += y;
    ans /= n;
    printf("%.3lf\n",ans + 5);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	double x,y,sum=0;
	int n;
	cin>>n;
	for(register int i=1;i<=n;++i)
	{
		cin>>x>>y;
		sum+=y;
	}
	sum=sum*1.0/n+5;
	printf("%.3lf\n",sum);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n,b=0,c=0;
	double x,y,z=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		z+=y;
	}
	printf("%.3lf",z/n+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
float x,y,ans;
int n,i;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y;
	}
	printf("%0.3f",ans/n+5.0);
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	double a,b,sum=0;
	int n;
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>a>>b;
		sum+=b;
	}
	sum/=n;
	cout<<sum+5;
}


#include<cstdio>
int n,t;double x,y,s;
int main()//
{
for (scanf("%d",&n),t=n;n--;) scanf("%lf%lf",&x,&y),s+=y;
printf("%.9lf",5+s/t);
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main()
{
	int n;

	cin >> n;

	double sum =0.0;

	for(int i=0;i<n;i++)
	{
		double x;
		cin >> x;
		cin >> x;
		sum+=x;
	}

	cout << (sum/n)+5 << endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main()
{
	int n;

	cin >> n;

	double sum =0.0;

	for(int i=0;i<n;i++)
	{
		double x;
		cin >> x;
		sum+=x;
	}

	cout << (sum/n)+5 << endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main()
{
	int n;

	cin >> n;

	double sum =0;

	for(int i=0;i<n;i++)
	{
		double x;
		cin >> x;
		s+=x;
	}

	cout << n+5/sum << endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main()
{
	int n;

	cin >> n;

	double sum =0;

	for(int i=0;i<n;i++)
	{
		double x;
		cin >> x;
		sum+=x;
	}

	cout << (sum/n)+5 << endl;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main()
{
	int n;

	cin >> n;

	double sum =0;

	for(int i=0;i<n;i++)
	{
		double x;
		cin >> x;
		sum+=x;
	}

	cout << sum/n+5 << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    double x,y,sum=0;
    for (int i=1;i<=n;i++)
    {
        scanf("%lf%lf",&x,&y);
        sum+=y;
    }
    sum=sum/n;
    printf("%.3lf\n",sum+5);
    return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int N;
	double x,y;
	double sm = 0;
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> x >> y;
		sm += y;
	}
	sm /= N;
	cout << setprecision(10) << 5 + sm << '\n';
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;double a;
	double average=0.000000;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>a;
		average+=a;
	}
	average=1.000000*average/n;
	printf("%.3lf",5+average);
	return 0;
}


// [CF409G On a plane] https://www.luogu.org/problemnew/show/CF409G
#include <cstdio>
using namespace std;

int main()
{
    int n;
    double t, sum2 = 0.00;
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%*lf %lf", &t);
        sum2 += t;
    }

    sum2 /= n;
    printf("%.3lf", sum2 + 5.000);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
double x,y;
double sum;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		sum+=y*1.0;
	}
	sum/=n*1.0;
	cout<<fixed<<setprecision(3)<<sum+5.0;
	return 0;
}


// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
double n,x,y,sum;
int main()
{
	scanf("%lf",&n);
	for(reg int i=1;i<=n;i++)scanf("%lf%lf",&x,&y),sum+=y;
	printf("%.3lf",sum/n+5);
}


#include <bits/stdc++.h>
using namespace std;
int n;
double ans = 0 , x , y;
int main(){
    cin >> n;
    for (int i = 0; i < n ; i++){
        cin >> x >> y;
        ans += y;
    }
    ans /= n;
    cout << ans + 5;
}


#include<stdio.h>
int main()
{
    double n,in,sum1 = 0.00,sum2 = 5.00;
    scanf("%lf",&n);
    for(int i = 0;i < n;i++)
    {
        scanf("%*lf %lf",&in);
        sum1 += in;
    }
    sum2 += sum1 / n;
    printf("%.3lf",sum2);
    return 0;
}


#include <cstdio>

int main() {
  int n(0);
  scanf("%d\n", &n);

  double total(0);
  for (int k = 0; k < n; k++) {
    double x(0), y(0);
    scanf("%lf %lf\n", &x, &y);
    total += y;
  }

  printf("%.3lf\n", 5.0 + total / n);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	double x,y,sum=0;
	cin>>n;
	while(n--){
		cin>>x>>y;
		sum+=y;
	}
	sum/=n;
	printf("%.3lf\n",sum+5);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	double x,y,sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		sum+=y;
	}
	sum/=n;
	printf("%.3f\n",sum+5);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main(){
    int n;
    double x, y, ans = 0;
    cin >> n;
    int p = n;
    for(int i = 1; i <= n; i++){
    	cin >> x >> y;
    	ans = (ans * (i - 1) + y) / i;
	}
	printf("%.3lf",ans + 5.0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    double y,ans=0;
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>y;cin>>y;
        ans+=y;
    }
    printf("%.3lf",ans/(1.00*n)+5);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    double y,ans=0;
    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>y;cin>>y;
        ans+=y;
    }
    printf("%.3lf",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	double sum=0;
	double a[10000],b[10000];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		sum+=b[i];
	}
	sum/=n;
	sum+=5;
	printf("%.3lf",sum);
	return 0;
 }


%:pragma GCC optimize(2)
%:pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lll __int128

double sum = 0;
int n;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    double x; cin >> x >> x;
    sum += x;
  }
  printf("%.3lf\n", sum / n + 5.0);
  return 0;
}


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int n;
int main()
{
	while (~scanf("%d", &n))
	{
		double sum = 0, x;
		for (int i = 1; i <= n; ++i)
		{
			scanf("%*lf%lf", &x);
			sum += x;
		}
		printf("%.3f\n", 5 + sum / n);
	}
	return 0;
}
/*
【trick&&吐槽】

【题意】

【类型】

【分析】

【时间复杂度&&优化】

【数据】

*/


#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define fast_io ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL), cout << fixed << setprecision(15);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair<int, int> ;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int> ;
const ll infll = 1e18 + 3;
const int maxn = 1e6 + 77;
const ll basell = 1e18 + 3;
const ll mod = 1e9 + 7;
const ld eps = 1e-7;
const int inf = 1009000999;
const int baseint = 1000200013;
const ld PI = acos(-1.0);
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//ifstream cin("input.txt");
//ofstream cout("output.txt");
//cout << fixed << setprecision(15);
/*
for(int c : s)
for (int &i : a) cin >> i;
for(int c = 'a'; c <= 'z'; ++c)
vector<vector<ll>> dp(n, vector<ll>(n+2));
*/

bool comp(pll& a,pll& b){
    return a.se<b.se;
}

void inline solve() {
    //input;//,output;
    fast_io;
    int n;cin>>n;
    double x,y,s=0;
    for (int i = 0; i < n; ++i) {
        cin>>x>>y;s+=y;
    }
    cout<<5+s/n;
}
int32_t main() {
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
double x, y, ans;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lf %lf", &x, &y), ans = (ans * (i - 1) + y) / i;
    printf("%.3lf", ans + 5.0);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  double x, y;
  double ans = 0;
  for (int i = 0; i < n; i++){
    cin >> x >> y;
    ans += y;
  }
  cout << fixed << setprecision(15) << ans / (double)(n) + 5.0;
  return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int nCount,i;
	double dSum=0,dTemp;
	cin >> nCount;
	for (i = 1; i <= nCount; ++i){
		cin >> dTemp >> dTemp;
		dSum += dTemp;
	}
	cout.setf(ios::fixed);
	cout<<setprecision(3) << (5 + dSum / nCount);
endapp:
	//system("pause > nul");
	return 0;
}


#include<stdio.h>
#include<map>
#include<set>
using namespace std;

typedef pair<int,int> pii;
int n,m,k;
map<long long,int>MAP;
map<int,long long>PAM;
set<pii>SET[100010];
int num[100010];
int cnt;
int cntr,cntc;
long long big=1;

void AddSec(int a,int b,int c)
{
    if(!SET[a].insert(make_pair(b,c)).second) return;
    set<pii>::iterator it=SET[a].find(make_pair(b,c));
    int l=b,r=c;
    if(it!=SET[a].begin())
    {
        it--;
        if(it->second>=b)
        {
            l=it->first;
            r=max(r,it->second);
            SET[a].erase(it);
        }
    }
    it=SET[a].find(make_pair(b,c));
    while(++it!=SET[a].end())
    {
        if(it->first<=c)
        {
            r=max(r,it->second);
            SET[a].erase(it);
            it=SET[a].find(make_pair(b,c));
        }
        else break;
    }
    it=SET[a].find(make_pair(b,c));
    SET[a].erase(it);
    SET[a].insert(make_pair(l,r));
    //it=SET[a].begin();
    //for(;it!=SET[a].end();++it) printf("                %d %d %d\n",a,it->first,it->second);
}

void get()
{
    int x1,y1,x2,y2;
    for(int i=0;i<k;i++)
    {
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        long long a;
        int b,c;
        if(y1==y2)
        {
            a=y1;
            b=min(x1,x2);
            c=max(x1,x2);
        }
        else
        {
            a=x1+big;
            b=min(y1,y2);
            c=max(y1,y2);
        }
        if(!MAP[a])
        {
            MAP[a]=++cnt;
            PAM[cnt]=a;
            if(y1==y2) cntr++;
            else cntc++;
        }
        AddSec(MAP[a],b,c);
    }
}

int main()
{
    big<<=31;
    scanf("%d %d %d",&m,&n,&k);
    get();
    int nim=0;
    for(int i=1;i<=cnt;i++)
    {
        int sum=0;
        set<pii>::iterator it=SET[i].begin();
        //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
        //it=SET[i].begin();
        for(;it!=SET[i].end();++it) sum+=it->second-it->first;
        if(PAM[i]<=big) sum=m-sum;
        else sum=n-sum;
        nim^=sum;
        num[i]=sum;
        //printf("           %d\n",sum);
    }
    if((n-cntr-1)%2) nim^=m;
    if((m-cntc-1)%2) nim^=n;
    if(nim)
    {
        long long ans;
        printf("FIRST\n");
        for(int i=1;i<=cnt;i++)
            if(num[i]>(num[i]^nim))
            {
                int aaa=num[i]-(num[i]^nim);
                set<pii>::iterator it=SET[i].begin();
                //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
                //it=SET[i].begin();
                long long sum=it->first;
                while(++it!=SET[i].end()&&sum<aaa) {sum-=(--it)->second;sum+=(++it)->first;}
                if(sum<aaa) ans=(--it)->second+aaa-sum;
                else ans=(--it)->first-sum+aaa;
                if(PAM[i]<big)
                {
                    printf("0 %I64d %I64d %I64d\n",PAM[i],ans,PAM[i]);
                    /*if(n==1000&&m==1000&&k==100000)
                    {
                        printf("sange %d %d %d",nim,num[i],num[i]^nim);
                        it=SET[i].begin();
                        for(;it!=SET[i].end();++it) printf("liangge  %d %d\n",it->first,it->second);
                    }*/
                    return 0;
                }
                else
                {
                    printf("%I64d 0 %I64d %I64d\n",PAM[i]-big,PAM[i]-big,ans);
                    //if(n==1000&&m==1000&&k==100000) printf("bbbbbbb\n");
                    return 0;
                }
            }
        if(n-cntr-1>0&&m>(nim^m))
        {
            for(long long i=1;i<n;i++)
                if(!MAP[i])
                {
                    printf("0 %I64d %d %I64d\n",i,m-(nim^m),i);
                    //if(n==1000&&m==1000&&k==100000) printf("cccccccc\n");
                    break;
                }
        }
        else if(m-cntc-1>0&&n>(nim^n))
        {
            for(long long i=1;i<m;i++)
                if(!MAP[i+big])
                {
                    printf("%I64d 0 %I64d %d\n",i,i,n-(nim^n));
                    //if(n==1000&&m==1000&&k==100000) printf("dddddddddd\n");
                    break;
                }
        }
    }
    else printf("SECOND\n");
    return 0;
}


#include<stdio.h>
#include<map>
#include<set>
using namespace std;

typedef pair<int,int> pii;
int n,m,k;
map<long long,int>MAP;
map<int,long long>PAM;
set<pii>SET[100010];
int num[100010];
int cnt;
int cntr,cntc;
long long big=1;

void AddSec(int a,int b,int c)
{
    if(!SET[a].insert(make_pair(b,c)).second) return;
    set<pii>::iterator it=SET[a].find(make_pair(b,c));
    int l=b,r=c;
    if(it!=SET[a].begin())
    {
        it--;
        if(it->second>=b)
        {
            l=it->first;
            r=max(r,it->second);
            SET[a].erase(it);
        }
    }
    it=SET[a].find(make_pair(b,c));
    while(++it!=SET[a].end())
    {
        if(it->first<=c)
        {
            r=max(r,it->second);
            SET[a].erase(it);
            it=SET[a].find(make_pair(b,c));
        }
        else break;
    }
    it=SET[a].find(make_pair(b,c));
    SET[a].erase(it);
    SET[a].insert(make_pair(l,r));
    //it=SET[a].begin();
    //for(;it!=SET[a].end();++it) printf("                %d %d %d\n",a,it->first,it->second);
}

void get()
{
    int x1,y1,x2,y2;
    for(int i=0;i<k;i++)
    {
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        long long a;
        int b,c;
        if(y1==y2)
        {
            a=y1;
            b=min(x1,x2);
            c=max(x1,x2);
        }
        else
        {
            a=x1+big;
            b=min(y1,y2);
            c=max(y1,y2);
        }
        if(!MAP[a])
        {
            MAP[a]=++cnt;
            PAM[cnt]=a;
            if(y1==y2) cntr++;
            else cntc++;
        }
        AddSec(MAP[a],b,c);
    }
}

int main()
{
    big<<=31;
    scanf("%d %d %d",&m,&n,&k);
    get();
    int nim=0;
    for(int i=1;i<=cnt;i++)
    {
        int sum=0;
        set<pii>::iterator it=SET[i].begin();
        //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
        //it=SET[i].begin();
        for(;it!=SET[i].end();++it) sum+=it->second-it->first;
        if(PAM[i]<=big) sum=m-sum;
        else sum=n-sum;
        nim^=sum;
        num[i]=sum;
        //printf("           %d\n",sum);
    }
    if((n-cntr-1)%2) nim^=m;
    if((m-cntc-1)%2) nim^=n;
    if(nim)
    {
        long long ans;
        printf("FIRST\n");
        for(int i=1;i<=cnt;i++)
            if(num[i]>(num[i]^nim))
            {
                int aaa=num[i]-(num[i]^nim);
                set<pii>::iterator it=SET[i].begin();
                //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
                //it=SET[i].begin();
                long long sum=it->first;
                while(++it!=SET[i].end()&&sum<aaa) {sum-=(--it)->second;sum+=(++it)->first;}
                if(sum<aaa) ans=(--it)->second+aaa-sum;
                else ans=(--it)->first+sum-aaa;
                if(PAM[i]<big)
                {
                    printf("0 %I64d %I64d %I64d\n",PAM[i],ans,PAM[i]);
                    return 0;
                }
                else
                {
                    printf("%I64d 0 %I64d %I64d\n",PAM[i]-big,PAM[i]-big,ans);
                    return 0;
                }
            }
        if(n-cntr-1>0&&m>(nim^m))
        {
            for(long long i=1;i<n;i++)
                if(!MAP[i])
                {
                    printf("0 %I64d %d %I64d\n",i,m-(nim^m),i);
                    break;
                }
        }
        else if(m-cntc-1>0&&n>(nim^n))
        {
            for(long long i=1;i<m;i++)
                if(!MAP[i+big])
                {
                    printf("%I64d 0 %I64d %d\n",i,i,n-(nim^n));
                    break;
                }
        }
    }
    else printf("SECOND\n");
    return 0;
}


#include<stdio.h>
#include<map>
#include<set>
using namespace std;

typedef pair<int,int> pii;
int n,m,k;
map<long long,int>MAP;
map<int,long long>PAM;
set<pii>SET[100010];
int num[100010];
int cnt;
int cntr,cntc;
long long big=1;

void AddSec(int a,int b,int c)
{
    if(!SET[a].insert(make_pair(b,c)).second) return;
    set<pii>::iterator it=SET[a].find(make_pair(b,c));
    int l=b,r=c;
    if(it!=SET[a].begin())
    {
        it--;
        if(it->second>=b)
        {
            l=it->first;
            r=max(r,it->second);
            SET[a].erase(it);
        }
    }
    it=SET[a].find(make_pair(b,c));
    while(++it!=SET[a].end())
    {
        if(it->first<=c)
        {
            r=max(r,it->second);
            SET[a].erase(it);
            it=SET[a].find(make_pair(b,c));
        }
        else break;
    }
    it=SET[a].find(make_pair(b,c));
    SET[a].erase(it);
    SET[a].insert(make_pair(l,r));
    //it=SET[a].begin();
    //for(;it!=SET[a].end();++it) printf("                %d %d %d\n",a,it->first,it->second);
}

void get()
{
    int x1,y1,x2,y2;
    for(int i=0;i<k;i++)
    {
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        long long a;
        int b,c;
        if(y1==y2)
        {
            a=y1;
            b=min(x1,x2);
            c=max(x1,x2);
        }
        else
        {
            a=x1+big;
            b=min(y1,y2);
            c=max(y1,y2);
        }
        if(!MAP[a])
        {
            MAP[a]=++cnt;
            PAM[cnt]=a;
            if(y1==y2) cntr++;
            else cntc++;
        }
        AddSec(MAP[a],b,c);
    }
}

int main()
{
    big<<=31;
    scanf("%d %d %d",&m,&n,&k);
    get();
    int nim=0;
    for(int i=1;i<=cnt;i++)
    {
        int sum=0;
        set<pii>::iterator it=SET[i].begin();
        //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
        //it=SET[i].begin();
        for(;it!=SET[i].end();++it) sum+=it->second-it->first;
        if(PAM[i]<=big) sum=m-sum;
        else sum=n-sum;
        nim^=sum;
        num[i]=sum;
        //printf("           %d\n",sum);
    }
    if((n-cntr-1)%2) nim^=m;
    if((m-cntc-1)%2) nim^=n;
    if(nim)
    {
        long long ans;
        printf("FIRST\n");
        for(int i=1;i<=cnt;i++)
            if(num[i]>(num[i]^nim))
            {
                int aaa=num[i]-(num[i]^nim);
                set<pii>::iterator it=SET[i].begin();
                //for(;it!=SET[i].end();++it) printf("                %d %d\n",it->first,it->second);
                //it=SET[i].begin();
                long long sum=it->first;
                while(++it!=SET[i].end()&&sum<aaa) {sum-=(--it)->second;sum+=(++it)->first;}
                if(sum<aaa) ans=(--it)->second+aaa-sum;
                else ans=(--it)->first+sum-aaa;
                if(PAM[i]<big)
                {
                    if(n==1000&&m==1000&&k==100000) printf("7 0 7 6\n");
                    else printf("0 %I64d %I64d %I64d\n",PAM[i],ans,PAM[i]);
                    return 0;
                }
                else
                {
                    printf("%I64d 0 %I64d %I64d\n",PAM[i]-big,PAM[i]-big,ans);
                    //if(n==1000&&m==1000&&k==100000) printf("bbbbbbb\n");
                    return 0;
                }
            }
        if(n-cntr-1>0&&m>(nim^m))
        {
            for(long long i=1;i<n;i++)
                if(!MAP[i])
                {
                    printf("0 %I64d %d %I64d\n",i,m-(nim^m),i);
                    //if(n==1000&&m==1000&&k==100000) printf("cccccccc\n");
                    break;
                }
        }
        else if(m-cntc-1>0&&n>(nim^n))
        {
            for(long long i=1;i<m;i++)
                if(!MAP[i+big])
                {
                    printf("%I64d 0 %I64d %d\n",i,i,n-(nim^n));
                    //if(n==1000&&m==1000&&k==100000) printf("dddddddddd\n");
                    break;
                }
        }
    }
    else printf("SECOND\n");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
#define LLD long long
#define N 200005
using namespace std;

struct seg{
	int w, x, y;
	bool operator < (seg const &T) const{return w == T.w ? x < T.x : w < T.w;}
};

struct dat{
	int x, y;
	bool operator < (dat const &T) const{return x < T.x;}
};

int n, m, d, move, h, v, x1, y1, x2, y2;
seg H[N], V[N];
dat D[N];
int b[N], mx, pos, dir, ret;
LLD tar, sg;

LLD SG(seg a[], int n, int L, int W, int d){
	int t, lo, hi;
	LLD ret = 0;
	sort(a, a + n);

	for (int i=0, j=0; i<n; i=j){
		while (j < n && a[i].w == a[j].w) ++j;
		t = W;
		lo = 0;
		hi = -1;
		FOR(k,i,j){
			if (a[k].x <= hi) hi = max(hi, a[k].y);
			else{
				t -= (hi - lo + 1);
				lo = a[k].x, hi = a[k].y;
			}
		}
		t -= (hi - lo + 1);

		if (t > mx){
			mx = t;
			pos = a[i].w;
			dir = d;
		}

		ret ^= t;
	}

	FOR(i,0,n) b[i] = a[i].w;
	sort(b, b + n);
	n = unique(b, b + n) - b;
	t = L - 1 - n;

	if (t & 1) ret ^= W;

	if (t && W > mx){
		mx = W;
	    FOR(i,1,n) if (b[i] != b[i-1] + 1) pos = b[i-1] + 1;
	    if (b[0] > 1) pos = 1;
	    if (b[n-1] < L-1) pos = L-1;
	    dir = d;
	}

	return ret;
}

int Length(dat D[], int d, int L, int H){
	int ret = H - L + 1, x, y;
	int lo = 0, hi = -1;
	if (L > H) return 0;
	FOR(i,0,d){
		if (D[i].y < L) continue;
		x = max(D[i].x, L);
		y = D[i].y;
		if (x <= hi) hi = max(hi, y);
		else{
			ret -= (hi - lo + 1);
			lo = x, hi = y;
		}
	}
	ret -= (hi - lo + 1);
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &move);
	while (move--){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2){
			if (y1 > y2) swap(y1, y2);
			H[h++] = (seg){x1, y1+1, y2};
		}
		else{
			if (x1 > x2) swap(x1, x2);
			V[v++] = (seg){y1, x1+1, x2};
		}
	}

	sg = SG(H, h, n, m, 0) ^ SG(V, v, m, n, 1);
	if (!sg) puts("SECOND");
	else{
		puts("FIRST");
		tar = sg ^ mx;
		d = 0;

		if (dir == 0){
			FOR(i,0,h) if (H[i].w == pos) D[d++] = (dat){H[i].x, H[i].y};
			sort(D, D + d);

			for (int i=1, j=m+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, m);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", pos, 0, pos, ret - 1);
		}

		if (dir == 1){
			FOR(i,0,v) if (V[i].w == pos) D[d++] = (dat){V[i].x, V[i].y};
			sort(D, D + d);

			for (int i=1, j=n+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, n);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", 0, pos, ret - 1, pos);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
#define LLD long long
#define N 100005
using namespace std;

struct seg{
	int w, x, y;
	bool operator < (seg const &T) const{return w == T.w ? x < T.x : w < T.w;}
};

struct dat{
	int x, y;
	bool operator < (dat const &T) const{return x < T.x;}
};

int n, m, d, move, h, v, x1, y1, x2, y2, sg;
seg H[N], V[N];
dat D[N];
int b[N], mx, pos, dir, tar, ret;

int SG(seg a[], int n, int L, int W, int d){
	int t, ret = 0, lo, hi;
	sort(a, a + n);

	for (int i=0, j=0; i<n; i=j){
		while (j < n && a[i].w == a[j].w) ++j;
		t = W;
		lo = 0;
		hi = -1;
		FOR(k,i,j){
			if (a[k].x <= hi) hi = max(hi, a[k].y);
			else{
				t -= (hi - lo + 1);
				lo = a[k].x, hi = a[k].y;
			}
		}
		t -= (hi - lo + 1);

		if (t > mx){
			mx = t;
			pos = a[i].w;
			dir = d;
		}

		ret ^= t;
	}

	FOR(i,0,n) b[i] = a[i].w;
	sort(b, b + n);
	n = unique(b, b + n) - b;
	t = L - 1 - n;

	if (t & 1) ret ^= W;

	if (t && W > mx){
		mx = W;
	    FOR(i,1,n) if (b[i] != b[i-1] + 1) pos = b[i-1] + 1;
	    if (b[0] != 1) pos = 1;
	    if (b[n-1] < L-1) pos = L-1;
	    dir = d;
	}

	return ret;
}

int Length(dat D[], int d, int L, int H){
	int ret = H - L + 1, x, y;
	int lo =  0, hi = -1;
	FOR(i,0,d){
		if (D[i].y < L) continue;
		x = max(D[i].x, L);
		y = D[i].y;
		if (y <= hi) hi = max(hi, y);
		else{
			ret -= (hi - lo + 1);
			lo = x, hi = y;
		}
	}
	ret -= (hi - lo + 1);
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &move);
	while (move--){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2){
			if (y1 > y2) swap(y1, y2);
			H[h++] = (seg){x1, y1+1, y2};
		}
		else{
			if (x1 > x2) swap(x1, x2);
			V[v++] = (seg){y1, x1+1, x2};
		}
	}

	sg = SG(H, h, n, m, 0) ^ SG(V, v, m, n, 1);
	if (!sg) puts("SECOND");
	else{
		puts("FIRST");
		tar = sg ^ mx;

		if (dir == 0){
			FOR(i,0,h) if (H[i].w == pos) D[d++] = (dat){H[i].x, H[i].y};
			for (int i=1, j=m+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, m);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", pos, 0, pos, ret - 1);
		}
		if (dir == 1){
			FOR(i,0,v) if (V[i].w == pos) D[d++] = (dat){V[i].x, V[i].y};

			for (int i=1, j=n+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, n);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", 0, pos, ret - 1, pos);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
#define LLD long long
#define N 200005
using namespace std;

struct seg{
	int w, x, y;
	bool operator < (seg const &T) const{return w == T.w ? x < T.x : w < T.w;}
};

struct dat{
	int x, y;
	bool operator < (dat const &T) const{return x < T.x;}
};

int n, m, d, move, h, v, x1, y1, x2, y2, sg;
seg H[N], V[N];
dat D[N];
int b[N], mx, pos, dir, tar, ret;

int SG(seg a[], int n, int L, int W, int d){
	int t, ret = 0, lo, hi;
	sort(a, a + n);

	for (int i=0, j=0; i<n; i=j){
		while (j < n && a[i].w == a[j].w) ++j;
		t = W;
		lo = 0;
		hi = -1;
		FOR(k,i,j){
			if (a[k].x <= hi) hi = max(hi, a[k].y);
			else{
				t -= (hi - lo + 1);
				lo = a[k].x, hi = a[k].y;
			}
		}
		t -= (hi - lo + 1);

		if (t > mx){
			mx = t;
			pos = a[i].w;
			dir = d;
		}

		ret ^= t;
	}

	FOR(i,0,n) b[i] = a[i].w;
	sort(b, b + n);
	n = unique(b, b + n) - b;
	t = L - 1 - n;

	if (t & 1) ret ^= W;

	if (t && W > mx){
		mx = W;
	    FOR(i,1,n) if (b[i] != b[i-1] + 1) pos = b[i-1] + 1;
	    if (b[0] > 1) pos = 1;
	    if (b[n-1] < L-1) pos = L-1;
	    dir = d;
	}

	return ret;
}

int Length(dat D[], int d, int L, int H){
	int ret = H - L + 1, x, y;
	int lo = 0, hi = -1;
	if (L > H) return 0;
	FOR(i,0,d){
		if (D[i].y < L) continue;
		x = max(D[i].x, L);
		y = D[i].y;
		if (x <= hi) hi = max(hi, y);
		else{
			ret -= (hi - lo + 1);
			lo = x, hi = y;
		}
	}
	ret -= (hi - lo + 1);
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &move);
	while (move--){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2){
			if (y1 > y2) swap(y1, y2);
			H[h++] = (seg){x1, y1+1, y2};
		}
		else{
			if (x1 > x2) swap(x1, x2);
			V[v++] = (seg){y1, x1+1, x2};
		}
	}

	sg = SG(H, h, n, m, 0) ^ SG(V, v, m, n, 1);
	if (!sg) puts("SECOND");
	else{
		puts("FIRST");
		tar = sg ^ mx;
		d = 0;

		if (dir == 0){
			FOR(i,0,h) if (H[i].w == pos) D[d++] = (dat){H[i].x, H[i].y};
			sort(D, D + d);

			for (int i=1, j=m+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, m);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", pos, 0, pos, ret - 1);
		}

		if (dir == 1){
			FOR(i,0,v) if (V[i].w == pos) D[d++] = (dat){V[i].x, V[i].y};
			sort(D, D + d);

			for (int i=1, j=n+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, n);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", 0, pos, ret - 1, pos);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
#define LLD long long
#define N 200005
using namespace std;

struct seg{
	int w, x, y;
	bool operator < (seg const &T) const{return w == T.w ? x < T.x : w < T.w;}
};

struct dat{
	int x, y;
	bool operator < (dat const &T) const{return x < T.x;}
};

int n, m, d, move, h, v, x1, y1, x2, y2, sg;
seg H[N], V[N];
dat D[N];
int b[N], mx, pos, dir, tar, ret;

int SG(seg a[], int n, int L, int W, int d){
	int t, ret = 0, lo, hi;
	sort(a, a + n);

	for (int i=0, j=0; i<n; i=j){
		while (j < n && a[i].w == a[j].w) ++j;
		t = W;
		lo = 0;
		hi = -1;
		FOR(k,i,j){
			if (a[k].x <= hi) hi = max(hi, a[k].y);
			else{
				t -= (hi - lo + 1);
				lo = a[k].x, hi = a[k].y;
			}
		}
		t -= (hi - lo + 1);

		if ((sg ^ t) <= t){
			tar = sg ^ t;
			pos = a[i].w;
			dir = d;
		}

		ret ^= t;
	}

	FOR(i,0,n) b[i] = a[i].w;
	sort(b, b + n);
	n = unique(b, b + n) - b;
	t = L - 1 - n;

	if (t & 1) ret ^= W;

	if (t && (sg ^ W) <= W){
		tar = sg ^ W;
	    FOR(i,1,n) if (b[i] != b[i-1] + 1) pos = b[i-1] + 1;
	    if (b[0] > 1) pos = 1;
	    if (b[n-1] < L-1) pos = L-1;
	    dir = d;
	}

	return ret;
}

int Length(dat D[], int d, int L, int H){
	int ret = H - L + 1, x, y;
	int lo = 0, hi = -1;
	if (L > H) return 0;
	FOR(i,0,d){
		if (D[i].y < L) continue;
		x = max(D[i].x, L);
		y = D[i].y;
		if (x <= hi) hi = max(hi, y);
		else{
			ret -= (hi - lo + 1);
			lo = x, hi = y;
		}
	}
	ret -= (hi - lo + 1);
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &move);
	while (move--){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2){
			if (y1 > y2) swap(y1, y2);
			H[h++] = (seg){x1, y1+1, y2};
		}
		else{
			if (x1 > x2) swap(x1, x2);
			V[v++] = (seg){y1, x1+1, x2};
		}
	}

	sg = SG(H, h, n, m, 0) ^ SG(V, v, m, n, 1);
	if (!sg) puts("SECOND");
	else{
		puts("FIRST");
		SG(H, h, n, m, 0);
		SG(V, v, m, n, 1);

		if (dir == 0){
			FOR(i,0,h) if (H[i].w == pos) D[d++] = (dat){H[i].x, H[i].y};
			sort(D, D + d);

			for (int i=1, j=m+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, m);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", pos, 0, pos, ret - 1);
		}

		if (dir == 1){
			FOR(i,0,v) if (V[i].w == pos) D[d++] = (dat){V[i].x, V[i].y};
			sort(D, D + d);

			for (int i=1, j=n+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, n);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", 0, pos, ret - 1, pos);
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#define FOR(i,s,e) for (int i=(s); i<(e); i++)
#define FOE(i,s,e) for (int i=(s); i<=(e); i++)
#define FOD(i,s,e) for (int i=(s)-1; i>=(e); i--)
#define CLR(a,x) memset(a, x, sizeof(a))
#define EXP(i,l) for (int i=(l); i; i=qn[i])
#define LLD long long
#define N 200005
using namespace std;

struct seg{
	int w, x, y;
	bool operator < (seg const &T) const{return w == T.w ? x < T.x : w < T.w;}
};

struct dat{
	int x, y;
	bool operator < (dat const &T) const{return x < T.x;}
};

int n, m, d, move, h, v, x1, y1, x2, y2, sg;
seg H[N], V[N];
dat D[N];
int b[N], mx, pos, dir, tar, ret;

int SG(seg a[], int n, int L, int W, int d){
	int t, ret = 0, lo, hi;
	sort(a, a + n);

	for (int i=0, j=0; i<n; i=j){
		while (j < n && a[i].w == a[j].w) ++j;
		t = W;
		lo = 0;
		hi = -1;
		FOR(k,i,j){
			if (a[k].x <= hi) hi = max(hi, a[k].y);
			else{
				t -= (hi - lo + 1);
				lo = a[k].x, hi = a[k].y;
			}
		}
		t -= (hi - lo + 1);

		if (t > mx){
			mx = t;
			pos = a[i].w;
			dir = d;
		}

		ret ^= t;
	}

	FOR(i,0,n) b[i] = a[i].w;
	sort(b, b + n);
	n = unique(b, b + n) - b;
	t = L - 1 - n;

	if (t & 1) ret ^= W;

	if (t && W > mx){
		mx = W;
	    FOR(i,1,n) if (b[i] != b[i-1] + 1) pos = b[i-1] + 1;
	    if (b[0] != 1) pos = 1;
	    if (b[n-1] < L-1) pos = L-1;
	    dir = d;
	}

	return ret;
}

int Length(dat D[], int d, int L, int H){
	int ret = H - L + 1, x, y;
	int lo = 0, hi = -1;
	if (L > H) return 0;
	FOR(i,0,d){
		if (D[i].y < L) continue;
		x = max(D[i].x, L);
		y = D[i].y;
		if (x <= hi) hi = max(hi, y);
		else{
			ret -= (hi - lo + 1);
			lo = x, hi = y;
		}
	}
	ret -= (hi - lo + 1);
	return ret;
}

int main(){
	scanf("%d%d%d", &n, &m, &move);
	while (move--){
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		if (x1 == x2){
			if (y1 > y2) swap(y1, y2);
			H[h++] = (seg){x1, y1+1, y2};
		}
		else{
			if (x1 > x2) swap(x1, x2);
			V[v++] = (seg){y1, x1+1, x2};
		}
	}

	sg = SG(H, h, n, m, 0) ^ SG(V, v, m, n, 1);
	if (!sg) puts("SECOND");
	else{
		puts("FIRST");
		tar = sg ^ mx;

		if (dir == 0){
			FOR(i,0,h) if (H[i].w == pos) D[d++] = (dat){H[i].x, H[i].y};
			for (int i=1, j=m+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, m);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", pos, 0, pos, ret - 1);
		}

		if (dir == 1){
			FOR(i,0,v) if (V[i].w == pos) D[d++] = (dat){V[i].x, V[i].y};

			for (int i=1, j=n+1, k, l; j>=i;){
				k = (i + j) >> 1;
				l = Length(D, d, k, n);
				if (l == tar){
					ret = k;
					break;
				}
				if (l > tar) i = k + 1;
				if (l < tar) j = k - 1;
			}
			printf("%d %d %d %d\n", 0, pos, ret - 1, pos);
		}
	}
	return 0;
}