#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;

int normal(int x) {
    int t = 20;
    while (x >= N) {
	x &= ~(1<<t);
	t--;
    }
    return x;
}

void MAIN() {
    scanf("%d", &N);

    REP (i, N) {
	int a = normal(i * 2);
	int b = normal(i * 2 + 1);
	printf("%d %d\n", a+1, b+1);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

const int N=50;
int t[N][N],s[N][N],sy,sx,highscore,dy[4]={-1,0,0,1},dx[4]={0,-1,1,0};
string highans;
using B=bitset<1500>;
const double TIMELIMIT=1.95*CLOCKS_PER_SEC;
clock_t start;

void dfs(int score,B used,int y,int x,string ans){
  if(clock()-start>TIMELIMIT){
    cout<<highans<<endl;
    exit(0);
  }
  REP(i,4){
    int Y=y+dy[i],X=x+dx[i];
    if(Y<0||Y>=N||X<0||X>=N||used[t[Y][X]])continue;
    dfs(score+s[Y][X],used|(B(1)<<t[Y][X]),Y,X,ans+"ULRD"[i]);
  }
  if(score>highscore){
    highscore=score;
    highans=ans;
  }
}

signed main(){
  start=clock();
  cin>>sy>>sx;
  REP(i,N)REP(j,N)cin>>t[i][j];
  REP(i,N)REP(j,N)cin>>s[i][j];
  dfs(0,B(1)<<t[sy][sx],sy,sx,"");
}
