591B.md (2737B)
1 Source: https://codeforces.com/problemset/problem/591/B 2 3 B. Rebranding 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. 22 23 For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. 24 25 Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. 26 27 Satisfy Arkady's curiosity and tell him the final version of the name. 28 29 Input 30 31 The first line of the input contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 200 000) — the length of the initial name and the number of designers hired, respectively. 32 33 The second line consists of *n* lowercase English letters and represents the original name of the corporation. 34 35 Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. 36 37 Output 38 39 Print the new name of the corporation. 40 41 Examples 42 43 Input 44 45 ``` 46 6 1 47 police 48 p m 49 ``` 50 51 Output 52 53 ``` 54 molice 55 ``` 56 57 Input 58 59 ``` 60 11 6 61 abacabadaba 62 a b 63 b c 64 a d 65 e g 66 f a 67 b b 68 ``` 69 70 Output 71 72 ``` 73 cdcbcdcfcdc 74 ``` 75 76 Note 77 78 In the second sample the name of the corporation consecutively changes as follows: 79 80  81 82  83 84  85 86  87 88  89 90 