// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i)
int main() {
int h, w, x, y;
cin >> h >> w >> x >> y;
x--, y--;
set<pii> r, c;
int n;
cin >> n;
rep(i, n) {
int a, b;
cin >> a >> b;
a--, b--;
r.insert(pii(a, b));
c.insert(pii(b, a));
}
int q;
cin >> q;
while (q--) {
char d;
int l;
cin >> d >> l;
if (d == 'L') {
int ty = max(y - l, 0);
auto cit = r.lower_bound(pii(x, y));
auto tit = r.lower_bound(pii(x, ty));
if (cit == tit) {
y = ty;
} else {
x = (*tit).first;
y = (*tit).second + 1;
}
}
if (d == 'R') {
int ty = min(y + l, w - 1);
auto cit = r.upper_bound(pii(x, y));
auto tit = r.upper_bound(pii(x, ty));
if (cit == tit) {
y = ty;
} else {
x = (*cit).first;
y = (*cit).second - 1;
}
}
if (d == 'U') {
int tx = max(x - l, 0);
auto cit = c.lower_bound(pii(y, x));
auto tit = c.lower_bound(pii(y, tx));
if (cit == tit) {
x = tx;
} else {
y = (*tit).first;
x = (*tit).second + 1;
}
}
if (d == 'D') {
int tx = min(x + l, h - 1);
auto cit = c.upper_bound(pii(y, x));
auto tit = c.upper_bound(pii(y, tx));
if (cit == tit) {
x = tx;
} else {
y = (*cit).first;
x = (*cit).second - 1;
}
}
printf("%d %d\n", x + 1, y + 1);
}
return 0;
}