#C5854. Replace Numbers with Squares

    ID: 49549 Type: Default 1000ms 256MiB

Replace Numbers with Squares

Replace Numbers with Squares

You are given a list of strings and a list of numbers. Your task is to replace every occurrence of each number (treated as a substring) in the given strings with its square. The square of a number \(n\) is defined as \(n^2\). Note that the replacement is done on the string level and each number will be replaced by its squared value even if the digits appear as part of a larger number.

For example, given the string "test2case3" and the numbers [2, 3]:

  • Replace "2" with "4" (since \(2^2 = 4\)).
  • Replace "3" with "9" (since \(3^2 = 9\)).

The final output will be: "test4case9".

inputFormat

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

  1. An integer \(T\) representing the number of strings.
  2. \(T\) lines follow, each containing a single string.
  3. An integer \(K\) representing the number of numbers.
  4. A single line with \(K\) space-separated integers.

It is guaranteed that all strings and numbers are valid.

outputFormat

For each input string, output the modified string on a new line after replacing each occurrence of every given number with its square.

The output should be sent to standard output (stdout).

## sample
1
hello1world
1
1
hello1world