#K91332. Swap Operations on a String

    ID: 37952 Type: Default 1000ms 256MiB

Swap Operations on a String

Swap Operations on a String

You are given a string and a list of swap operations. Each swap operation is represented by a pair of indices \( (P, Q) \), where both \( P \) and \( Q \) are 0-indexed positions in the string. For each operation, swap the characters at positions \( P \) and \( Q \). If no operations are provided, the string remains unchanged.

Note: Each swap operation should be performed in the order they are given.

For example:

  • For the string abc and swap operation (0, 2), the resulting string is cba.
  • For the string abcd and swap operations (0, 1), (1, 2), (2, 3), the resulting string is bcda.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains the initial string \( S \).
  2. The second line contains an integer \( N \), the number of swap operations.
  3. The next \( N \) lines each contain two integers \( P \) and \( Q \), representing a swap operation.

Indices are 0-indexed.

outputFormat

Output the resulting string after performing all swap operations on the initial string. The output should be written to standard output.

## sample
abc
1
0 2
cba