#C189. Keyword Replacement

    ID: 45144 Type: Default 1000ms 256MiB

Keyword Replacement

Keyword Replacement

You are given a text string and a sequence of replacement pairs. For each pair \( (a, b) \), replace all occurrences of the substring a in the text with b. The replacements are applied sequentially in the order they are provided.

For example, given the text "The quick brown fox jumps over the lazy dog" and the replacement pairs (quick, swift), (brown, dark), and (jumps, leaps), the resulting text will be "The swift dark fox leaps over the lazy dog".

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

  • The first line contains the original text string \( s \).
  • The second line contains an integer \( n \), representing the number of replacement pairs.
  • Each of the next \( n \) lines contains two space-separated strings: the target substring and its replacement.

outputFormat

Output to standard output (stdout) the modified text string after performing all the replacement operations.

## sample
The quick brown fox jumps over the lazy dog
3
quick swift
brown dark
jumps leaps
The swift dark fox leaps over the lazy dog