import java.util.*;
import java.io.*;
//Solution Credits: Taranpreet Singh
class Editorial{
//SOLUTION BEGIN
//Offline Solution - O(NlogN+MlogM)
int n = ni(), m = ni();
long[][] inte = new long[n][];
for(int i = 0; i< n; i++)inte[i] = new long[]{nl(), nl()};
//Sorted intervals by right end.
Arrays.
sort(inte,
(long[] l0,
long[] l1
) -> Long.
compare(l0
[1], l1
[1])); long[][] qq = new long[m][2];
long[] ans = new long[m];
for(int i = 0; i< m; i++){
qq[i][0] = i;
qq[i][1] = nl();
}
//Sorted queries by their time.
Arrays.
sort(qq,
(long[] l0,
long[] l1
) -> Long.
compare(l0
[1], l1
[1])); int query = 0;
for(int interval = 0;interval<n; interval++){
while(query<m && qq[query][1]<inte[interval][1]){
if(qq[query][1]< inte[interval][0])//If query doesn't belong to interval.
ans[(int)qq[query][0]] = inte[interval][0]-qq[query][1];
query++;
}
}
//Handling those query times, which will not served food.
while(query<m)ans[(int)qq[query++][0]] = -1;
//Printing answer
for(long l:ans)pn(l);
}
//SOLUTION ENDS
boolean multipleTC = true;
in = new FastReader();
for(int i = 1, T = (multipleTC)?ni():1; i<= T; i++)solve(i);
out.flush();
out.close();
}
new Editorial().run();
}
void p
(Object o
){out.
print(o
);} void pn
(Object o
){out.
println(o
);} void pni
(Object o
){out.
println(o
);out.
flush();} String nln
(){return in.
nextLine();} int ni
(){return Integer.
parseInt(in.
next());} long nl
(){return Long.
parseLong(in.
next());} double nd
(){return Double.
parseDouble(in.
next());} class FastReader{
public FastReader(){
}
}
while (st == null || !st.hasMoreElements()){
try{
e.printStackTrace();
}
}
return st.nextToken();
}
try{
str = br.readLine();
e.printStackTrace();
}
return str;
}
}
}
ICAgIGltcG9ydCBqYXZhLnV0aWwuKjsKICAgIGltcG9ydCBqYXZhLmlvLio7CiAgICAvL1NvbHV0aW9uIENyZWRpdHM6IFRhcmFucHJlZXQgU2luZ2gKICAgIGNsYXNzIEVkaXRvcmlhbHsKICAgICAgICAvL1NPTFVUSU9OIEJFR0lOCiAgICAgICAgdm9pZCBzb2x2ZShpbnQgVEMpIHRocm93cyBFeGNlcHRpb257CiAgICAgICAgICAgIC8vT2ZmbGluZSBTb2x1dGlvbiAtIE8oTmxvZ04rTWxvZ00pCiAgICAgICAgICAgIGludCBuID0gbmkoKSwgbSA9IG5pKCk7CiAgICAgICAgICAgIGxvbmdbXVtdIGludGUgPSBuZXcgbG9uZ1tuXVtdOwogICAgICAgICAgICBmb3IoaW50IGkgPSAwOyBpPCBuOyBpKyspaW50ZVtpXSA9IG5ldyBsb25nW117bmwoKSwgbmwoKX07CiAgICAgICAgICAgIC8vU29ydGVkIGludGVydmFscyBieSByaWdodCBlbmQuCiAgICAgICAgICAgIEFycmF5cy5zb3J0KGludGUsIChsb25nW10gbDAsIGxvbmdbXSBsMSkgLT4gTG9uZy5jb21wYXJlKGwwWzFdLCBsMVsxXSkpOwogICAgICAgICAgICBsb25nW11bXSBxcSA9IG5ldyBsb25nW21dWzJdOwogICAgICAgICAgICBsb25nW10gYW5zID0gbmV3IGxvbmdbbV07CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7IGk8IG07IGkrKyl7CiAgICAgICAgICAgICAgICBxcVtpXVswXSA9IGk7CiAgICAgICAgICAgICAgICBxcVtpXVsxXSA9IG5sKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy9Tb3J0ZWQgcXVlcmllcyBieSB0aGVpciB0aW1lLgogICAgICAgICAgICBBcnJheXMuc29ydChxcSwgKGxvbmdbXSBsMCwgbG9uZ1tdIGwxKSAtPiBMb25nLmNvbXBhcmUobDBbMV0sIGwxWzFdKSk7CiAgICAgICAgICAgIGludCBxdWVyeSA9IDA7CiAgICAgICAgICAgIGZvcihpbnQgaW50ZXJ2YWwgPSAwO2ludGVydmFsPG47IGludGVydmFsKyspewogICAgICAgICAgICAgICAgd2hpbGUocXVlcnk8bSAmJiBxcVtxdWVyeV1bMV08aW50ZVtpbnRlcnZhbF1bMV0pewogICAgICAgICAgICAgICAgICAgIGlmKHFxW3F1ZXJ5XVsxXTwgaW50ZVtpbnRlcnZhbF1bMF0pLy9JZiBxdWVyeSBkb2Vzbid0IGJlbG9uZyB0byBpbnRlcnZhbC4KICAgICAgICAgICAgICAgICAgICAgICAgYW5zWyhpbnQpcXFbcXVlcnldWzBdXSA9IGludGVbaW50ZXJ2YWxdWzBdLXFxW3F1ZXJ5XVsxXTsKICAgICAgICAgICAgICAgICAgICBxdWVyeSsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIC8vSGFuZGxpbmcgdGhvc2UgcXVlcnkgdGltZXMsIHdoaWNoIHdpbGwgbm90IHNlcnZlZCBmb29kLgogICAgICAgICAgICB3aGlsZShxdWVyeTxtKWFuc1soaW50KXFxW3F1ZXJ5KytdWzBdXSA9IC0xOwogICAgICAgICAgICAvL1ByaW50aW5nIGFuc3dlcgogICAgICAgICAgICBmb3IobG9uZyBsOmFucylwbihsKTsKICAgICAgICB9CiAgICAgICAgLy9TT0xVVElPTiBFTkRTCiAgICAgICAgYm9vbGVhbiBtdWx0aXBsZVRDID0gdHJ1ZTsKICAgICAgICBGYXN0UmVhZGVyIGluO1ByaW50V3JpdGVyIG91dDsKICAgICAgICB2b2lkIHJ1bigpIHRocm93cyBFeGNlcHRpb257CiAgICAgICAgICAgIGluID0gbmV3IEZhc3RSZWFkZXIoKTsKICAgICAgICAgICAgb3V0ID0gbmV3IFByaW50V3JpdGVyKFN5c3RlbS5vdXQpOwogICAgICAgICAgICBmb3IoaW50IGkgPSAxLCBUID0gKG11bHRpcGxlVEMpP25pKCk6MTsgaTw9IFQ7IGkrKylzb2x2ZShpKTsKICAgICAgICAgICAgb3V0LmZsdXNoKCk7CiAgICAgICAgICAgIG91dC5jbG9zZSgpOwogICAgICAgIH0KICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB0aHJvd3MgRXhjZXB0aW9uewogICAgICAgICAgICBuZXcgRWRpdG9yaWFsKCkucnVuKCk7CiAgICAgICAgfQogICAgICAgIHZvaWQgcChPYmplY3Qgbyl7b3V0LnByaW50KG8pO30KICAgICAgICB2b2lkIHBuKE9iamVjdCBvKXtvdXQucHJpbnRsbihvKTt9CiAgICAgICAgdm9pZCBwbmkoT2JqZWN0IG8pe291dC5wcmludGxuKG8pO291dC5mbHVzaCgpO30KICAgICAgICBTdHJpbmcgbigpe3JldHVybiBpbi5uZXh0KCk7fQogICAgICAgIFN0cmluZyBubG4oKXtyZXR1cm4gaW4ubmV4dExpbmUoKTt9CiAgICAgICAgaW50IG5pKCl7cmV0dXJuIEludGVnZXIucGFyc2VJbnQoaW4ubmV4dCgpKTt9CiAgICAgICAgbG9uZyBubCgpe3JldHVybiBMb25nLnBhcnNlTG9uZyhpbi5uZXh0KCkpO30KICAgICAgICBkb3VibGUgbmQoKXtyZXR1cm4gRG91YmxlLnBhcnNlRG91YmxlKGluLm5leHQoKSk7fQogICAgICAgIGNsYXNzIEZhc3RSZWFkZXJ7CiAgICAgICAgICAgIEJ1ZmZlcmVkUmVhZGVyIGJyOwogICAgICAgICAgICBTdHJpbmdUb2tlbml6ZXIgc3Q7CiAgICAgICAgICAgIHB1YmxpYyBGYXN0UmVhZGVyKCl7CiAgICAgICAgICAgICAgICBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIoU3lzdGVtLmluKSk7CiAgICAgICAgICAgIH0KICAgICAKICAgICAgICAgICAgcHVibGljIEZhc3RSZWFkZXIoU3RyaW5nIHMpIHRocm93cyBFeGNlcHRpb257CiAgICAgICAgICAgICAgICBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgRmlsZVJlYWRlcihzKSk7CiAgICAgICAgICAgIH0KICAgICAKICAgICAgICAgICAgU3RyaW5nIG5leHQoKXsKICAgICAgICAgICAgICAgIHdoaWxlIChzdCA9PSBudWxsIHx8ICFzdC5oYXNNb3JlRWxlbWVudHMoKSl7CiAgICAgICAgICAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICAgICAgICAgICBzdCA9IG5ldyBTdHJpbmdUb2tlbml6ZXIoYnIucmVhZExpbmUoKSk7CiAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChJT0V4Y2VwdGlvbiAgZSl7CiAgICAgICAgICAgICAgICAgICAgICAgIGUucHJpbnRTdGFja1RyYWNlKCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmV0dXJuIHN0Lm5leHRUb2tlbigpOwogICAgICAgICAgICB9CiAgICAgCiAgICAgICAgICAgIFN0cmluZyBuZXh0TGluZSgpewogICAgICAgICAgICAgICAgU3RyaW5nIHN0ciA9ICIiOwogICAgICAgICAgICAgICAgdHJ5eyAgICAKICAgICAgICAgICAgICAgICAgICBzdHIgPSBici5yZWFkTGluZSgpOwogICAgICAgICAgICAgICAgfWNhdGNoIChJT0V4Y2VwdGlvbiBlKXsKICAgICAgICAgICAgICAgICAgICBlLnByaW50U3RhY2tUcmFjZSgpOwogICAgICAgICAgICAgICAgfSAgIAogICAgICAgICAgICAgICAgcmV0dXJuIHN0cjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0g