{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q+,R+,S+,T-,V+,X+}
{$M 65520,0,655360}
program eiluciu_tapatinimas;
  { Knuth-Morris-Pratt algoritmas }
  const PR = 'REDAKT.DAT';
        RZ = 'REDAKT.REZ';
        MAX_F = 20000; { maksimalus fragmento ilgis }
        ILGIS = 80;  { maksimalus simboli— skai‡ius eilut‚je }
  type  eilute = array [1..MAX_F] of char;
        lentele = array [1..MAX_F] of integer;

  { ‘emiau apražyti globalieji kintamieji }
  var eil_t,       { teksto eilu‡i— skai‡ius }
      m: longint;  { fragmento ilgis }
      F: eilute;   { pats fragmentas }
      pi: lentele; { priežd‚li— lentel‚ }
      rasta: boolean; { ar fragmentas rastas nors vien… kart… }

  procedure priesdeliu_skaiciavimas (var pi: lentele);
     { apskai‡iuoja priežd‚li— lentelŠ }
     var k, q: longint;
  begin
      pi[1] := 0;
      k := 0;
      for q := 2 to m do { skai‡iuosime pi[q] reikžmŠ }
        begin
           while (k > 0) and (F[k+1] <> F[q])
             do k := pi[k];
           if F[k+1] = F[q]
              then k := k + 1;
           pi[q] := k;
        end;
    end; { priežd‚li—_skai‡iavimas }

  procedure KMP_algoritmas (var f1, f2: text; eil_t: longint;
                            const F: eilute; var rasta: boolean);
    var pi: lentele;
        poz, q, i, j, eil, stu: longint;
        T: string;
  begin
    priesdeliu_skaiciavimas (pi);
    rasta := false;
    q := 0;
    for i := 1 to eil_t do
      begin
        readln (f1, T); { perskaitoma tolesn‚ eilut‚ }
        for j := 1 to length(T) do
          begin
            while (q > 0) and (F[q+1] <> T[j]) do
              q := pi[q];
            if F[q+1] = T[j]
               then q := q + 1;
            if q = m
               then begin
                      rasta := true;
                      poz := (i - 1)*ILGIS + j - 1;
                      poz := poz - m + 1;
                      eil := poz div ILGIS + 1;
                      stu := poz mod ILGIS + 1;
                      writeln (f2, eil, ' ',stu);
                      q := pi[q];
                    end
          end;
      end;
  end; { KMP algoritmas }

  procedure skaityti (var f1: text; var eil_t: longint;
                      var F: eilute);
  { skaitomi pradiniai duomenys }
    var eil_f, i, j: longint;
        s: string;
  begin
    assign (f1, PR);
    reset (f1);
    readln (f1, eil_f, eil_t);
    m := 0;
    for i := 1 to eil_f do
      begin
        readln (f1, s);
        for j := 1 to length(s) do
          F[m+j] := s[j];
          m := m + length(s);
      end;
  end; { skaityti }

  var f1, f2: text;
begin
  skaityti (f1, eil_t, F);
  { rezultat— byla atidaroma ražymui }
  assign (f2, RZ);
  rewrite (f2);
  KMP_algoritmas (f1, f2, eil_t, F, rasta);
  if not rasta
     then writeln (f2, 0);
  close (f1);
  close (f2);
end.



