// 洛谷中不需要输出方案的标程
// 方案记录在ans中
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x)
{
x = 0; char ch = 0; int f = 1;
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
x *= f;
}
template <class T>
void write(T x)
{
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + 48);
}
template <class T>
void writeln(T x)
{
write(x), puts("");
}
const int N = 1e5 + 5;
const char dir[] = "UDLR";
set< pair<int, int> > A[N], B[N];
int R, C, n;
int a[N], b[N], c[N], d[N];
bool vis[N];
set< pair<int, int> >::iterator it;
vector< pair< pair<int, int>, pair<char, char> > > ans;
bool move(int x, int y, char d)
{
if (d == 'D')
{
it = B[y].lower_bound(make_pair(x + 1, 0));
return it != B[y].end();
}
else if (d == 'U')
{
it = B[y].lower_bound(make_pair(x, 0));
if (it == B[y].begin()) return 0;
else return it--, 1;
}
else if (d == 'L')
{
it = A[x].lower_bound(make_pair(y, 0));
if (it == A[x].begin()) return 0;
else return it--, 1;
}
else
{
it = A[x].lower_bound(make_pair(y + 1, 0));
return it != A[x].end();
}
return 0;
}
bool check(int x, int y)
{
set< pair<int, int> >::iterator it = A[x].lower_bound(make_pair(y, 0));
return (*it).first == y;
}
void del(int j)
{
A[a[j]].erase(make_pair(b[j], j)), B[b[j]].erase(make_pair(a[j], j));
A[c[j]].erase(make_pair(d[j], j)), B[d[j]].erase(make_pair(c[j], j));
}
void solve1()
{
int m; read(m);
int ans = 0;
for (int i = 1; i <= m; i++)
{
int x, y; read(x), read(y);
if (check(x, y)) continue;
char dir1[5], dir2[5]; scanf("%s %s", dir1, dir2);
if (!move(x, y, dir1[0])) continue;
set< pair<int, int> >::iterator it1 = it;
if (!move(x, y, dir2[0])) continue;
set< pair<int, int> >::iterator it2 = it;
if ((*it1).second == (*it2).second)
{
ans++;
vis[(*it1).second] = 1;
del((*it1).second);
}
}
write(ans), putchar(' ');
for (int i = 1; i <= n; i++)
if (vis[i]) {
A[a[i]].insert(make_pair(b[i], i)), A[c[i]].insert(make_pair(d[i], i));
B[b[i]].insert(make_pair(a[i], i)), B[d[i]].insert(make_pair(c[i], i));
vis[i] = 0;
}
}
bool update(int i)
{ // i is color
int X1 = a[i], Y1 = b[i], X2 = c[i], Y2 = d[i], cnt = 0;
if (X1 == X2)
{
if (Y1 > Y2) swap(Y1, Y2);
if (Y1 + 1 == Y2) return 0;
move(4, 1, 'R');
if (move(X1, Y1, 'R'))
{
if ((*it).second == i)
{
del(i);
ans.push_back(make_pair(make_pair(X1, Y1 + 1), make_pair('L', 'R')));
return 1;
}
}
return 0;
}
if (Y1 == Y2)
{
if (X1 > X2) swap(X1, X2);
if (X1 + 1 == X2) return 0;
if (move(X1, Y1, 'D'))
if ((*it).second == i)
{
del(i);
ans.push_back(make_pair(make_pair(X1 + 1, Y1), make_pair('U', 'D')));
return 1;
}
return 0;
}
char opt[6];
if (!check(X2, Y1))
{
for (int j = 0; j < 4; j++)
if (move(X2, Y1, dir[j]))
if ((*it).second == i) opt[cnt] = dir[j];
if (cnt >= 2)
{
ans.push_back(make_pair(make_pair(X2, Y1), make_pair(opt[1], opt[2])));
del(i);
return 1;
}
}
cnt = 0;
if (!check(X1, Y2))
{
for (int j = 0; j < 4; j)
if (move(X1, Y2, dir[j]))
if ((*it).second == i) opt[++cnt] = dir[j];
if (cnt >= 2)
{
ans.push_back(make_pair(make_pair(X1, Y2), make_pair(opt[1], opt[2])));
del(i);
return 1;
}
}
return 0;
}
void solve2()
{
ans.clear();
queue<int> q;
for (int i = 1; i <= n; i++)
if (update(i)) q.push(i), vis[i] = 1;
while (!q.empty()) {
int k = q.front();
q.pop();
int color[10];
int t = 0;
for (int i = 0; i < 4; i++)
{
if (move(a[k], b[k], dir[i]))
color[t] = (*it).second;
if (move(c[k], d[k], dir[i]))
color[t] = (*it).second;
}
for (int i = 1; i <= t; i)
{
if (!vis[color[i]] && update(color[i])) {
q.push(color[i]);
vis[color[i]] = 1;
del(color[i]);
}
}
}
writeln(ans.size());
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
#ifdef chhokmah
freopen("eliminate1.in", "r", stdin);
#endif
read(R), read(C), read(n);
for (int i = 1; i <= n; i)
{
read(a[i]), read(b[i]), read(c[i]), read(d[i]);
A[a[i]].insert(make_pair(b[i], i)), A[c[i]].insert(make_pair(d[i], i));
B[b[i]].insert(make_pair(a[i], i)), B[d[i]].insert(make_pair(c[i], i));
vis[i] = 0;
}
solve1();
solve2();
return 0;
}