inline ll rd(){ ll x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
vector<int> s;
intmain(){ for (int i = 1, x = 0; i <= 9; ++i) { x = i * 110000000; s.push_back(x); for (int j = 0; j <= 99; ++j) { if (j) {x = x / 100000 * 100000 + 100000; s.push_back(x);} for (int k = 0; k <= 9; ++k) { if (k) {x = x / 100000 * 100000 + k * 11000; s.push_back(x);} for (int l = 0; l <= 9; ++l) { if (l) {x = x / 1000 * 1000 + l * 101; s.push_back(x);} for (int r = 1; r <= 9; ++r) if (r) {x += 10; s.push_back(x);} } } } } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); int n = rd(); printf("%d\n", s[n - 1]); return0; }
inlinevoidinv(int p){ // reverse first p elements and last n - p elements tmp = s; s = r.substr(n - p, p) + r.substr(0, n - p); r = tmp.substr(p, n - p) + tmp.substr(0, p); // reversed sequence }
inline ll rd(){ ll x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
intmain(){ int H = rd(), W = rd(); vector<int> r(H, 0), c(W, 0); vector<vector<char>> a(H, vector<char>(W)); for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) { char c = getchar(); while (!isalpha(c)) c = getchar(); a[i][j] = c; } int n = rd(), r0 = 0, r1 = 1, c0 = 0, c1 = 1; auto upd = [&](int &pos, int m, int p) {pos = (pos > p) * m + p - pos;};
for (int i = 1; i <= n; ++i) { int x = rd() - 1, y = rd() - 1; upd(r1, H, x); upd(r0, H, x); upd(c1, W, y); upd(c0, W, y); }
if (r1 == (r0 + 1) % H) for (int i = 0; i < H; ++i) r[(r0 + i) % H] = i; elsefor (int i = 0; i < H; ++i) r[(r0 + H - i) % H] = i;
if (c1 == (c0 + 1) % W) for (int i = 0; i < W; ++i) c[(c0 + i) % W] = i; elsefor (int i = 0; i < W; ++i) c[(c0 + W - i) % W] = i;
for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) putchar(a[r[i]][c[j]]); puts(""); } return0; }