{
task FestB
lang PASCAL
}
Program FestB;
        Type
            AOC=Array [0..255] of 0..255;
            AOP=Array [0..255] of 0..255;
            TypeMN=0..255;
        Var
           Q,Sum:-1000..1000;
           M,I,N:TypeMN;
           A:AOC;B,Rearranged:AOP;
           S,Best,Position:array [0..255] of -255..255;
        Procedure Rearrange(M:TypeMN;Coord:AOC;Enter:AOP;Var Rearr:AOP);
                  Var
                     P:TypeMN;
                  Begin
                       For P:=1 to M Do
                           Rearr[Coord[P]]:=Rearr[Coord[P]]+Enter[P];
                  End;
        Begin
             Readln (M,N);
             For I:=1 to M Do Readln(A[I],B[I]);
             For I:=1 to N Do Readln(S[I]);
             Rearrange(M,A,B,Rearranged);
             For Q:=-1000 to 1000 Do Begin
                 Sum:=0;
                 For I:=1 to 255 Do
                         Sum:=Sum+abs(I-Q)*Rearranged[I];
                 For I:=1 to N Do Begin
                     If abs(S[I]-Sum)<abs(S[I]-Best[I]) Then Begin
                        Best[I]:=Sum;Position[I]:=Q;
                     End;
                 End;
             End;
             For I:=1 to N Do Writeln(Position[I],' ',abs(S[I]-Best[I]));
        End.