#include <bits/stdc++.h>
using namespace std;
/*
单词翻转 A:每次把第 l 到第 r 个单词首尾颠倒。
一个单词翻转两次就回到原样,所以只要知道每个单词被翻转了奇数次还是偶数次。
用差分(异或)统计每个位置的翻转次数的奇偶性即可。
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<string> w(n);
for (string &s : w) cin >> s;
vector<int> diff(n + 2, 0);
for (int i = 0; i < q; i++) {
int l, r;
cin >> l >> r;
diff[l] ^= 1;
diff[r + 1] ^= 1;
}
int parity = 0;
for (int i = 1; i <= n; i++) {
parity ^= diff[i];
if (parity) reverse(w[i - 1].begin(), w[i - 1].end());
cout << w[i - 1] << "\n";
}
return 0;
}