#pragma GCC optimize("Ofast")
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;
char a[2500505];
char b[2500505];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> a;
int n = (int)strlen(a);
memcpy(b, a, n);
reverse(b, b + n);
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
swap_ranges(a + l - 1, a + r, b + n - r);
}
cout << a << endl;
return 0;
}
I3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKCiMgaW5jbHVkZSA8aW9zdHJlYW0+CiMgaW5jbHVkZSA8YWxnb3JpdGhtPgojIGluY2x1ZGUgPGNzdHJpbmc+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2hhciBhWzI1MDA1MDVdOwpjaGFyIGJbMjUwMDUwNV07CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKICAgIAogICAgY2luID4+IGE7CiAgICBpbnQgbiA9IChpbnQpc3RybGVuKGEpOwogICAgbWVtY3B5KGIsIGEsIG4pOwogICAgcmV2ZXJzZShiLCBiICsgbik7CiAgICBpbnQgcTsKICAgIGNpbiA+PiBxOwogICAgd2hpbGUgKHEtLSkgewogICAgICAgIGludCBsLCByOwogICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgc3dhcF9yYW5nZXMoYSArIGwgLSAxLCBhICsgciwgYiArIG4gLSByKTsKICAgIH0KICAgIGNvdXQgPDwgYSA8PCBlbmRsOwogICAgCiAgICByZXR1cm4gMDsKfQ==