{$apptype console}
uses
  SysUtils, Math, testlib;

var
  n, k : integer;
  a, b : array[1..1000] of integer;
  c : integer;
  i, j : integer;
  l, r, d : integer;

begin
  n := inf.readLongint();
  k := inf.readLongint();
  for i := 1 to n do begin
    a[i] := inf.readLongint();
  end;
  for i := 1 to n do begin
    b[i] := inf.readLongint();
  end;
  c := ouf.readLongint();
  if (c >= n) then begin
    quit(_wa, format('Number of moves is %d >= n ', [c]));
  end;
  for i := 1 to c do begin
    l := ouf.readLongint();
    r := ouf.readLongint();
    d := ouf.readLongint();
    if (l < 1) or (l > n) then begin
      quit(_wa, format('On operation %d l is out of bounds: %d', [i, l]));
    end;
    if (r < 1) or (r > n) then begin
      quit(_wa, format('On operation %d r is out of bounds: %d', [i, r]));
    end;
    if (l > r) then begin
      quit(_wa, format('On operation %d l > r: %d > %d', [i, l, r]));
    end;
    if (d < 0) or (d >= k) then begin
      quit(_wa, format('On operation %d d is out of bounds: %d', [i, d]));
    end;
    for j := l to r do begin
      a[j] := (a[j] + d) mod k;
    end;
  end;
  for i := 1 to n do begin
    if (a[i] <> b[i]) then begin
      quit(_wa, format('Sequences differ at position %d: a[i] = %d, b[i] = %d', [i, a[i], b[i]]));
    end;
  end;
  quit(_ok, format('n = %d, k = %d', [n, k]));
end.