#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<ll, vector<ll>> hh, ww;
ll h, w, rs, cs, r, s, l;
int n, q;
char x;
int main()
{
cin >> h >> w >> rs >> cs;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> r >> s;
hh[r].push_back(s);
ww[s].push_back(r);
}
for (auto &p : hh)p.second.push_back(0),p.second.push_back(w+1);
for (auto &p : ww)p.second.push_back(0),p.second.push_back(h+1);
for (auto &p : hh)
sort(p.second.begin(), p.second.end());
for (auto &p : ww)
sort(p.second.begin(), p.second.end());
cin >> q;
for (int i = 1; i <= q; i++)
{
cin >> x >> l;
if (x == 'U')
{
auto itt = ww.find(cs);
if (itt != ww.end())
{
auto it = lower_bound(ww[cs].begin(), ww[cs].end(),rs);
if (*it>rs)
{
it--;
rs=max(rs-l,*it+1);
}
else
rs = max((ll)1, rs - l);
}
else
rs = max((ll)1, rs - l);
}
if (x == 'D')
{
auto itt = ww.find(cs);
if (itt != ww.end())
{
auto it = lower_bound(ww[cs].begin(), ww[cs].end(), rs);
if (*it > rs && (*it <= min(rs + l, h)))
{
rs = *it - 1;
}
else
rs = min(rs + l, h);
}
else
rs = min(rs + l, h);
}
if (x == 'L')
{
auto itt = hh.find(rs);
if (itt != hh.end())
{
auto it = lower_bound(hh[rs].begin(), hh[rs].end(),cs);
if (*it > cs )
{
it--;
cs=max(cs-l,*it+1);
}
else
cs = max((ll)1, cs - l);
}
else
cs = max((ll)1, cs - l);
}
if (x == 'R')
{
auto itt = hh.find(rs);
if (itt != hh.end())
{
auto it = lower_bound(hh[rs].begin(), hh[rs].end(), cs);
if (*it > cs && (*it <= min(w, cs + l)))
{
cs = *it - 1;
}
else
cs = min(w, cs + l);
}
else
cs = min(w, cs + l);
}
cout << rs << " " << cs << endl;
}
system("pause");
return 0;
}