Timofey completed a course on algorithms and studied many different types of sorting. He still encounters new and unusual sorting algorithms. Every time Timofey learns a new sorting algorithm, he needs to practice on a binary string. Usually, during practice, he chooses a sequence of substrings and sorts them one by one, but sometimes this sequence turns out to be very large, and Timofey cannot practice on long strings. Timofey decided to speed up this process by performing some operations in parallel and learned about the following sorting method. It uses a system of N parallel pipelines of length M, numbered from top to bottom from 1 to N, with one bit fed into each of them.
| ==================================== |
|
| | | |
=== |
| ==================================== |
| |
| | | | |
=== |
| ==================================== |
| |
| | |
=== |
| ==================================== |
|
| A system of 4 pipelines |
Invalid arrangement of jumpers |
The pipelines are denoted by the = symbols, and the jumpers connecting adjacent pipelines are denoted by the | symbols. Two jumpers touching the same pipeline cannot be in the same column. All N bits move simultaneously along the pipelines from left to right at the same speed. When the bits reach a jumper, it sorts them. That is, the smaller bit goes to the upper pipeline, and the larger one — to the lower one. For example:
The system takes a binary string of length N, where the i-th bit is fed into the i-th pipeline. The bits travel to the end of the pipelines, after which a binary string of length N is also obtained. Timofey has Q binary strings of length N on which he was going to practice. Help determine for each string what string will be obtained at the output of the system.
Input
The first line contains three integers N, M, Q (1 ≤ N, M, Q ≤ 3000) — the number of pipelines, the length of the pipelines, and the number of Timofey’s binary strings.
From the second to the 2 · N-th line of the input data, the pipeline system is given. The even-numbered lines contain the pipelines, each consisting of M = characters, and the odd-numbered lines consist of M | characters and spaces. In a single column, there are no two jumpers touching the same pipeline.
The following Q lines contain binary strings of length N that Timofey wants to pass through the system.
Output
Output Q binary strings obtained after passing through the system.
Samples
| input | output |
|---|
4 36 4
====================================
| |
====================================
| | |
====================================
|
====================================
0110
1000
1011
0111
| 0011
0010
0111
0111
|
2 3 2
===
|
===
10
01
| 01
01
|
5 32 6
================================
| | ||
================================
| | |
================================
| | |
================================
| |
================================
10000
11000
11100
11110
10101
01101
| 00001
00101
01101
01111
00111
00111
|
4 4 3
====
| |
====
| |
====
| |
====
0101
1000
1101
| 0011
0001
0111
|
Problem Author: Timofey Imaev
Problem Source: The 2026 ICPC Ural Qualification