#include <bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#endif
using namespace std;
#define int long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int sz = 3e5 + 5, inf = 1e9, mod = 998244353;
vector<int> g[sz], order;
int par[sz], dp1[sz], dp2[sz];
bool used[sz];
int find(int a){
if (par[a] < 0) return a;
return par[a] = find(par[a]);
}
void unite(int a, int b){
a = find(a);
b = find(b);
if (a == b) return;
if (par[a] > par[b]) swap(a, b);
par[a] += par[b];
par[b] = a;
}
void toposort(int node){
used[node] = 1;
for (int to : g[node]) {
if (!used[to]) {
toposort(to);
}
}
order.push_back(node);
}
void _(){
int n, m, v;
cin >> n >> m >> v;
for (int i = 1; i <= m; i++) par[i] = -1;
vector<pair<int, int>> edge;
for (int i = 1; i <= v; i++) {
int a, b;
char c;
cin >> a >> c >> b;
if (c == '<') {
edge.push_back({a, b});
} else {
unite(a, b);
}
}
for (auto [a, b] : edge) {
a = find(a);
b = find(b);
if (a != b) {
g[a].push_back(b);
}
}
for (int i = 1; i <= m; i++) {
if (!used[i]) {
toposort(i);
}
}
for (auto x : order) {
for (auto to : g[x]) {
dp2[x] = max(dp2[x], dp2[to] + 1);
}
}
reverse(all(order));
for (auto x : order) {
for (auto to : g[x]) {
dp1[to] = max(dp1[to], dp1[x] + 1);
}
}
for (int i = 1; i <= m; i++) {
int r = find(i);
if (dp1[r] + dp2[r] + 1 == n) {
cout << "K" << dp1[r] + 1 << endl;
} else cout << "?\n";
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
int T = 1;
// cin >> T;
while (T--) _();
}
// By Riyad