{ NOTE: it is recommended to use this even if you don't understand the following code }

const
    MAXN = 100000;
    MAXM = 100000;
    MAXK = 1000000; { sum of all K[i] }

var
    N, M, i, j, pos : LongInt;

    C : Array[0..MAXM-1] of LongInt;

    K     : Array[0..MAXN-1] of LongInt;
    start : Array[0..MAXN] of LongInt;

    P, S  : Array[0..MAXK-1] of LongInt;

    T     : Array[0..MAXM-1] of LongInt;

begin
{
    uncomment the two following lines if you want to read/write from files
    assign(input,  'input.txt');  reset(input);
    assign(output, 'output.txt'); rewrite(output);
}

    ReadLn(N, M);

    for i := 0 to M-1 do
        Read(C[i]);
    ReadLn;

    pos := 0;

    for i := 0 to N-1 do
    begin
        ReadLn(K[i]);
        start[i] := pos;

        for j := 0 to K[i]-1 do
        begin
            ReadLn(P[pos], S[pos]);
            Inc(pos);
        end;
    end;

    start[N] := pos;

    for i := 0 to M-1 do
        T[i] := 0;

    { INSERT YOUR CODE HERE }

    { example access pattern:
      for i := 0 to N-1 do
          for j := start[i] to start[i+1]-1 do
              use P[j], S[j]
    }

    for i := 0 to M-1 do
        Write(T[i], ' ');
    WriteLn;

end.
