#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define getrp() ({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);}) #define rd() ({long _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;}) #define wt(v) ({ulong _z=v;do*--wp=_z%10+48;while(_z/=10);}) #define rep(v,e) for(long v=0;v>8|a[i]<<56; } }else{ for(int i=0;i>40|a[i]<<24; } } } void sort(ulong*a,int n){ ulong*b=a+n; sort_aux(a,b,n,0); sort_aux(b,a,n,0); sort_aux(a,b,n,0); sort_aux(b,a,n,1); } ulong e[300000*2]; ulong b0,b1[1<<6],b2[1<<12]; void initb(){ b0=~0ul; rep(i,1<<6){ b1[i]=~0ul; } rep(i,1<<12){ b2[i]=~0ul; } } int c[100000]; int r[100000]; unsigned wd[10000]; char wdlz[10000]; void mkwd(){ unsigned v='0000'; long i=0; rep(a,10){ rep(b,10){ rep(c,10){ rep(d,10){ wd[i++]=v; v+=1<<24; } v+=(1<<16)-(10<<24); } v+=(1<<8)-(10<<16); } v+=(1<<0)-(10<<8); } rep(j,1000) wdlz[j]=1; rep(j,100) wdlz[j]=2; rep(j,10) wdlz[j]=3; } int main(){ char*rp=getrp(); long n=rd(); long j=0; rep(i,n){ long l=rd(); long r=rd(); long a=rd(); if(a<100000){ e[j++]=a<<32|l<<2|0; e[j++]=a<<32|r<<2|2; } } long q=rd(); rep(i,q){ long x=rd(); e[j++]=i<<32|x<<2|1; } sort(e,j); initb(); rep(i,j){ long t=e[i]&3; long a=e[i]>>32; if(t==0){ if(!c[a]++){ if(!(b2[a>>6]&=~(1ul<>12]&=~(1ul<<(a>>6)))){ b0&=~(1ul<<(a>>12)); } } } } if(t==1){ long d=ctz(b0); d=d<<6|ctz(b1[d]); d=d<<6|ctz(b2[d]); r[a]=d; } if(t==2){ if(!--c[a]){ b2[a>>6]|=1ul<>12]|=1ul<<(a>>6); b0|=1ul<<(a>>12); } } } mkwd(); { char*wp=wbuf+sizeof wbuf; rrep(i,q){ *--wp='\n'; long v=r[i]; if(v>=10000){ wp-=4; *(unsigned*)wp=wd[v%10000]; v/=10000; } wp-=4; *(unsigned*)wp=wd[v]; wp+=wdlz[v]; } write(1,wp,wbuf+sizeof wbuf-wp); } _exit(0); }