F - XOR Table

4

32 votes
Approved, Easy-Medium
Problem

Let's consider a two-dimensional binary table A of N rows and M columns. Let Ai,j denote a bit in the i-th row and j-th column. Rows are numbered 0 through N1 from top to bottom. Columns are numbered 0 through M1 from left to right.

You are given dimensions N, M, and the 0-th row of the table. You are also given an integer P (0<P<M) and a bit X (0X1). The following equation holds for every i,j that 0iN2, 0jM1: Ai,jX=Ai,(j+P)%mAi+1,(j+P)%m Here, denotes the exclusive or logical operation.

Your task is to find the (N1)-th row of the table. If there are multiple correct answers, output any of them. It can be proved that there exists at least one table satisfying the given conditions.

Input format

The first line of the input contains one integer T denoting the number of test cases.

The first line of each test case description contains four integers N, M, P and X.

The second line contains a binary string of M bits denoting the 0-th row of the table A.

Output format

For each test case, output a single line containing a binary string of M bits denoting the (N1)-th row of the table A. If there are multiple correct answers, output any of them.

Constraints

  • 1T8
  • 1N109
  • 2M106
  • 0<P<M
  • 0X1

Subtasks

Extra constraints Points Which tests
N10 10 1
M10 20 2
M50000 30 3
no extra constraints 40 4
Time Limit: 6
Memory Limit: 256
Source Limit:
Explanation

For the first test case of the sample input, the following table A satisfies the conditions given in the statement:

10111
10101
00111

So, one of the possible outputs for this particular test case is 00111.

Stack Limit for C++ is 8MB. You are allowed to increase it in your code, e.g. using setrlimit().

Editor Image

?