#include <iostream>
#include <queue>
#include <string>
#include <random>
using namespace std;

int maze[50][50];
bool used[50][50];
//"RDUL"
string moves = "RDUL";
int dx[4] = {0,1,-1,0};
int dy[4] = {1,0,0,-1};
int vals[50][50];
string fans = "";
long long fscore = 0;
const int inf = 1e9;

void dfs(int depth,int x,int y,string now,long long score){
    used[x][y] = true;
    score += (long long)vals[x][y];
    if (depth == 0){
        if (fscore < score){
            fscore = score;
            fans = now;
        }
        return;
    }
    int badx = -1,bady = -1;
    for (int k = 0; k < 4;k++){
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (0 <= nx && nx < 50 && 0 <= ny && ny < 50 
                && maze[nx][ny] == maze[x][y]){
                    if (!used[nx][ny]){
                        badx = nx;
                        bady = ny;
                    } 
                    used[nx][ny] = true;
        }
    }
    vector<bool> can(4);
    vector<pair<int,int>> topoint(4);
    for (int k = 0; k < 4;k++){
        int nx = x + dx[k];
        int ny = y + dy[k];
        topoint[k] = {nx,ny};
        if (0 <= nx && nx < 50 && 0 <= ny && ny < 50 
            && maze[nx][ny] != maze[x][y] && !used[nx][ny]){
                can[k] = true;
            }
    }
    bool candoit = false;
    for (int k = 0; k < 4;k++){
        if (can[k]) {
            candoit = true;
            dfs(depth-1,topoint[k].first,topoint[k].second,now+moves[k],score);
        }
    }
    if (candoit){
        if (fscore < score){
            fscore = score;
            fans = now;
        }
        return;
    }
    if (badx > 0){
        used[badx][bady] = false;
    }
    used[x][y] = false;

}



int main(){
    int sx,sy; // start point
    cin >> sx >> sy;
    for (int i = 0; i < 50;i++){
        for (int j = 0; j < 50;j++){
            cin >> maze[i][j];
        }
    }
    for (int i = 0; i < 50;i++){
        for (int j = 0; j < 50;j++){
            cin >> vals[i][j];
        }
    }
    for (int k = 0; k < 4;k++){
        int nx = sx + dx[k];
        int ny = sy + dy[k];
        if (0 <= nx && nx < 50 && 0 <= ny && ny < 50 
                && maze[nx][ny] == maze[sx][sy]){
                    used[nx][ny] = true;
        }
    }
    dfs(inf,sx,sy,"",0);
    cout << fans << endl;
   

    return 0;
}
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

const int nax = 107;
vector<int> G[nax];
vector<int> tin(nax);
set<pair<int, int>> SCC_edges_orientation;
int counter = 1;

void dfs(int u, int p) {
  tin[u] = counter;
  counter++;
  for (auto &v : G[u]) {
    if (v == p) {
      continue;
    }
    if (tin[v] == 0) {
      SCC_edges_orientation.emplace(u, v);
      dfs(v, u);
    } else if (tin[v] < tin[u]) {
      SCC_edges_orientation.emplace(u, v);
    }
  }
}

int main() {
  _upgrade;
  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> edges(m);
  vector<string> direction(m);
  vector<int> reachable_cnt(n);

  for (auto &p : edges) {
    cin >> p.first >> p.second;
    p.first--;
    p.second--;
  }
  for (auto &v : reachable_cnt) {
    cin >> v;
  }

  for (int i = 0; i < m; i++) {
    int u = edges[i].first;
    int v = edges[i].second;
    if (reachable_cnt[u] < reachable_cnt[v]) {
      direction[i] = "<-";
    } else if (reachable_cnt[u] > reachable_cnt[v]) {
      direction[i] = "->";
    } else {
      G[u].push_back(v);
      G[v].push_back(u);
    }
  }

  for (int i = 0; i < n; i++) {
    if (tin[i] == 0) {
      dfs(i, -1);
    }
  }

  for (int i = 0; i < m; i++) {
    if (direction[i] != "") {
      continue;
    }
    if (SCC_edges_orientation.find(edges[i]) != SCC_edges_orientation.end()) {
      direction[i] = "->";
    } else {
      direction[i] = "<-";
    }
  }

  for (auto &dir : direction) {
    cout << dir << "\n";
  }
  return 0;
}