importjava.io.*;importjava.util.*;publicclassStuckInARut{staticfinalintmyINF=1000000007;publicstaticvoidmain(String[]args)throwsIOException{StuckInARut.Kattioio=newStuckInARut.Kattio();IntegerN=io.nextInteger();ArrayList<ArrayList<Integer>>east=newArrayList<ArrayList<Integer>>();ArrayList<ArrayList<Integer>>north=newArrayList<ArrayList<Integer>>();ArrayList<ArrayList<Integer>>pos=newArrayList<ArrayList<Integer>>();for(Integeri=0;i<N;i++){Stringd=io.next();Integerx=io.nextInteger();Integery=io.nextInteger();ArrayList<Integer>p=newArrayList<Integer>();p.add(x);p.add(y);pos.add(p);p.add(i);if(d.compareTo("E")==0){east.add(p);}else{north.add(p);}}ArrayList<ArrayList<Integer>>meetTime=newArrayList<ArrayList<Integer>>();for(ArrayList<Integer>nC:north){for(ArrayList<Integer>eC:east){IntegeryT=eC.get(1)-nC.get(1);IntegerxT=nC.get(0)-eC.get(0);if(xT==yT){continue;}if(yT>xT&&xT>0){meetTime.add(newArrayList<Integer>(Arrays.asList(yT,nC.get(2),eC.get(2),0)));}elseif(yT<xT&&yT>0){meetTime.add(newArrayList<Integer>(Arrays.asList(xT,eC.get(2),nC.get(2),1)));}}}Collections.sort(meetTime,newComparator<ArrayList<Integer>>(){publicintcompare(ArrayList<Integer>s1,ArrayList<Integer>s2){returnInteger.compare(s1.get(0),s2.get(0));}});ArrayList<Integer>ans=newArrayList<Integer>(Collections.nCopies(N,myINF));for(ArrayList<Integer>mt:meetTime){if(ans.get(mt.get(2))==myINF&&ans.get(mt.get(1))==myINF){// both not stoppedans.set(mt.get(1),mt.get(0));continue;}if(ans.get(mt.get(1))==myINF){// not yet assignedif(mt.get(3)==1){Integerstart=pos.get(mt.get(2)).get(1);Integerend=start+ans.get(mt.get(2));if(pos.get(mt.get(1)).get(1)>=start&&pos.get(mt.get(1)).get(1)<=end){ans.set(mt.get(1),mt.get(0));}}else{Integerstart=pos.get(mt.get(2)).get(0);Integerend=start+ans.get(mt.get(2));if(pos.get(mt.get(1)).get(0)>=start&&pos.get(mt.get(1)).get(0)<=end){ans.set(mt.get(1),mt.get(0));}}}}for(Integerv:ans){if(v==myINF){io.println("Infinity");}else{io.println(v);}}io.close();}// https://usaco.guide/general/io?lang=java#io-templatestaticclassKattioextendsPrintWriter{privateBufferedReaderr;privateStringTokenizerst;// standard inputpublicKattio(){this(System.in,System.out);}publicKattio(InputStreami,OutputStreamo){super(o);r=newBufferedReader(newInputStreamReader(i));}// USACO-style file inputpublicKattio(StringproblemName)throwsIOException{super(newFileWriter(problemName+".out"));r=newBufferedReader(newFileReader(problemName+".in"));}// returns null if no more inputpublicStringnext(){try{while(st==null||!st.hasMoreTokens())st=newStringTokenizer(r.readLine());returnst.nextToken();}catch(Exceptione){}returnnull;}publicintnextInteger(){returnInteger.parseInt(next());}publicdoublenextDouble(){returnDouble.parseDouble(next());}publiclongnextLong(){returnLong.parseLong(next());}}}
#include <bits/stdc++.h>
#include <bits/stdc++.h>
usingnamespacestd;vector<array<int,3>>north;vector<array<int,3>>east;intmyINF=1e9;#define f first
#define s second
intmain(){intN;cin>>N;vector<pair<int,int>>pos(N);for(inti=0;i<N;i++){chard;cin>>d;pair<int,int>p;cin>>p.first>>p.second;array<int,3>varr={p.f,p.s,i};if(d=='E'){east.push_back(varr);}else{north.push_back(varr);}pos[i]=p;}vector<vector<int>>meetTime;for(autonC:north){for(autoeC:east){intyT=eC[1]-nC[1];intxT=nC[0]-eC[0];if(xT==yT){continue;}if(yT>xT&&xT>0){meetTime.push_back({yT,nC[2],eC[2],0});}elseif(yT<xT&&yT>0){meetTime.push_back({xT,eC[2],nC[2],1});}}}sort(meetTime.begin(),meetTime.end());vector<int>ans(N,myINF);for(automt:meetTime){if(ans[mt[2]]==myINF&&ans[mt[1]]==myINF){// both not stoppedans[mt[1]]=mt[0];continue;}if(ans[mt[1]]==myINF){// not yet assignedif(mt[3]){intstart=pos[mt[2]].s;intend=start+ans[mt[2]];if(pos[mt[1]].s>=start&&pos[mt[1]].s<=end){ans[mt[1]]=mt[0];}}else{intstart=pos[mt[2]].f;intend=start+ans[mt[2]];if(pos[mt[1]].f>=start&&pos[mt[1]].f<=end){ans[mt[1]]=mt[0];}}}}for(autov:ans){if(v==myINF){cout<<"Infinity"<<endl;}else{cout<<v<<endl;}}}