{
TASK:FESTB
LANG:PASCAL
}
program festb;
type mas_pos=array[-1000..1000]of integer;
     mas_money=array[0..10000]of integer;
var h:mas_pos;
    e:mas_pos;
    s:mas_money;
    p:mas_money;
    z,q,i,j,n,m,k,l,t:integer;
begin
q:=0;
readln(m,n);
for i:=1 to m do
begin
readln(k,t);
h[k]:=h[k]+t;
end;
for i:=1 to n do
readln(s[i]);
for i:=1 to n do
p[i]:=10000;
for i:=1 to n do
begin
     for j:=-1000 to 1000 do
     begin
          for l:=-1000 to 1000 do
          if h[l]>0 then
          begin
             if j<0 then
                if l<0 then
                   q:=q+abs(abs(l)-abs(j))*h[l];
             if j<0 then
                if l>0 then
                   q:=q+abs(abs(l)+abs(j))*h[l];
             if j>0 then
                if l<0 then
                   q:=q+abs(abs(l)+abs(j))*h[l];
             if j>0 then
                if l>0 then
                   q:=q+abs(l-j)*h[l];
          end;
          if abs(s[i]-q)<p[i] then
          begin
               p[i]:=abs(s[i]-q);
               e[i]:=j;
               q:=0;
          end
          else q:=0;
     end;
end;

for i:=1 to n do
writeln(e[i],' ',p[i]);
readln;
end.
