#include<cstdio>
#include<stdlib.h>
#include<utility>
#include<ctime>
#define MOD 1000000007
using namespace std;

class Node{
public:
    long long key;
    int heap;

    int cnt;
    int ord;

    Node* fiuSt;
    Node* fiuDr;

    Node (long long a,int b){
        key=a;
        heap=b;
        ord=cnt=1;
        fiuSt=fiuDr=NULL;
    }
};

pair<Node*,Node*> split(Node* treap,long long val){
    pair<Node*,Node*> ans;

    if (treap==NULL){
        ans.first=ans.second=NULL;
        return ans;
    }
    else
    if (treap-> key<val){
        pair<Node*,Node*> aux=split(treap-> fiuDr,val);

        ans.first=treap;
        treap-> fiuDr=aux.first;
        ans.second=aux.second;
    }
    else {
        pair<Node*,Node*> aux=split(treap-> fiuSt,val);

        ans.second=treap;
        treap-> fiuSt=aux.second;
        ans.first=aux.first;
    }

    treap-> cnt=treap-> ord;
    if (treap-> fiuSt!=NULL) treap-> cnt+=treap-> fiuSt-> cnt;
    if (treap-> fiuDr!=NULL) treap-> cnt+=treap-> fiuDr-> cnt;

    return ans;
}

Node* join(Node* treapSt,Node* treapDr){
    Node* ans;

    if (treapDr==NULL) return treapSt;
    if (treapSt==NULL) return treapDr;

    if (treapSt-> heap<treapDr -> heap){
        ans=treapSt;
        ans-> fiuDr=join(treapSt-> fiuDr,treapDr);
    }
    else
    if (treapSt-> heap>treapDr -> heap){
        ans=treapDr;
        ans-> fiuSt=join(treapSt,treapDr-> fiuSt);
    }

    ans-> cnt=ans-> ord;
    if (ans-> fiuSt!=NULL) ans-> cnt+=ans-> fiuSt-> cnt;
    if (ans-> fiuDr!=NULL) ans-> cnt+=ans-> fiuDr-> cnt;

    return ans;
}

Node* insert(Node* treap,Node* nod){
    if (treap==NULL) return nod;

    if (nod-> heap<treap-> heap){
        nod-> fiuSt=treap;

        nod-> cnt=nod-> ord;
        if (nod-> fiuSt!=NULL) nod-> cnt+=nod-> fiuSt-> cnt;
        if (nod-> fiuDr!=NULL) nod-> cnt+=nod-> fiuDr-> cnt;

        return nod;
    }

    treap-> fiuDr=insert(treap-> fiuDr,nod);

    treap-> cnt=treap-> ord;
    if (treap-> fiuSt!=NULL) treap-> cnt+=treap-> fiuSt-> cnt;
    if (treap-> fiuDr!=NULL) treap-> cnt+=treap-> fiuDr-> cnt;

    return treap;
}

Node* add(Node* treap,long long val){
    Node* ans;

    if (treap==NULL) return NULL;

    if (treap-> key==val){
        treap-> ord++;
        ans=treap;
    }
    else
    if (treap-> key>val) ans=add(treap-> fiuSt,val);
    else
    if (treap-> key<val) ans=add(treap-> fiuDr,val);

    treap-> cnt=treap-> ord;
    if (treap-> fiuSt!=NULL) treap-> cnt+=treap-> fiuSt-> cnt;
    if (treap-> fiuDr!=NULL) treap-> cnt+=treap-> fiuDr-> cnt;

    return ans;
}

Node* nth(Node* treap,int ind){
    if (treap==NULL) return NULL;

    if (treap-> fiuSt!=NULL){
        if (treap-> fiuSt-> cnt>=ind) return nth(treap-> fiuSt,ind);
        else ind-=treap-> fiuSt-> cnt;
    }

    if (treap-> ord>=ind) return treap;

    return nth(treap-> fiuDr,ind-treap-> ord);
}

int main(){
    freopen ("pitricele.in","r",stdin);
    freopen ("pitricele.out","w",stdout);
    int n,i;

    long long sum=0;
    long long prec=0;
    long long g,r,x;

    srand(time(NULL));

    Node* treap=NULL;

    scanf ("%d",&n);

    for(i=1;i<=n;i++){
        scanf ("%lld%lld%lld",&g,&r,&x);
        g^=prec;
        r^=prec;
        x^=prec;

        sum+=g;

        Node* aux=add(treap,sum+r);
        if (aux==NULL){
            aux=new Node(sum+r,rand()%MOD+1);

            pair<Node*,Node*> t1=split(treap,sum+r);
            t1.first=insert(t1.first,aux);
            treap=join(t1.first,t1.second);
        }

        aux=nth(treap,(int)x);
        if (aux==NULL) return -1;

        prec=aux-> key-sum;

        printf ("%lld\n",prec);
    }

    return 0;
}
