#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     }     return a.first > b.first;   }   int main() {     string s;     int n, m;     cin >> n >> m;     cin >> s;     char ara[m + 1], ara1[m + 1];     for (int i = 0; i < m; i++) {       char x, y;       cin >> x >> y;       ara[i] = x;       ara1[i] = y;     }     char str[27], str1[27];     int j = 0;     for (char ch =  a ; ch <=  z ; ch++) {       char ch1;       ch1 = ch;       int f = 0;       for (int i = 0; i < m; i++) {         if (ara[i] == ch1) {           str[j] = ara1[i];           ch1 = ara1[i];           f = 1;         } else if (ara1[i] == ch1) {           str[j] = ara[i];           ch1 = ara[i];           f = 1;         }       }       if (f == 1) {         str1[j] = ch;         j++;       }       f = 0;     }     str[j] =   0 ;     str1[j] =   0 ;     string st = (string)str;     string st1 = (string)str1;     int l1 = st1.size();     for (int j = 0; j < n; j++) {       for (int i = 0; i < l1; i++) {         if (s[j] == st1[i]) {           s[j] = st[i];           break;         }       }     }     cout << s;     return 0;   }   