#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}
inline long long LSB(long long a){
    return a & -a;
}
class BIT{
    std::vector<long long> bit;
    int n;
public:
    BIT(int n):n(n){
        bit=std::vector<long long>(n,0);
    }

    void add(int a,long long b){
        a++;
        for(long long i = a; i <= n; i+=LSB(i)){
            bit[i-1]+=b;
        }
    }
    void set(int a,long long b){
        ll prev = this->get(a);
        a++;
        for(long long i = a; i <= n; i+=LSB(i)){
            bit[i-1]+=b-prev;
        }
    }
    long long sum(int a){
        if(a<0)return 0;
        if(a>=n)a=n-1;
        a++;
        long long ret=0;
        for(long long i = a; i > 0; i-=LSB(i)){
            ret+=bit[i-1];
        }
        return ret;
    }
    long long sum(int a,int b){
        // [a,b)
        --b;
        if(a==0)return sum(b);
        return sum(b)-sum(a-1);
    }
    long long get(int a){
        if(a==0)return sum(0);
        return sum(a)-sum(a-1);
    }
};

void solve(long long H, long long W, long long M, std::vector<long long> X, std::vector<long long> Y){
  ll rt=W,lb=H;
  vector<pll> XY(M);
  REP(M){
    XY[i]=pll(X[i],Y[i]);
  }
  vector<ll> mh(H,W),mw(W,H);
  REP(M){
    if(X[i]==0){
      chmin(rt,Y[i]);
    }
    chmin(mh[X[i]],Y[i]);
    if(Y[i]==0){
      chmin(lb,X[i]);
    }
    chmin(mw[Y[i]],X[i]);
  }
  if(rt==1&&lb==1){
    cout<<1<<endl;
    return;
  }
  BIT wl(W),hl(H);
  ll ans=0;
  sort(XY.begin(),XY.end());
  ll idx=0;
  REP(lb){
    while(idx<XY.size()&&XY[idx].first==i){
      wl.set(XY[idx].second,1);
      ++idx;
    }
    ans+=mh[i]+max(0LL,(rt-mh[i]-wl.sum(mh[i],rt)));
  }
  REP(rt){
    if(mw[i]>=lb){
      ans+=mw[i]-lb;
    }
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    std::vector<long long> Y(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
        scanf("%lld",&Y[i]);
        --X[i];--Y[i];
    }
    solve(H, W, M, std::move(X), std::move(Y));
    return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_REVERSE(x) SORT(x);reverse(all(x))

double calc_score(int direction, const int &ci, const int &cj, int base) {
    bool isUpperSide = ci < 25;
    bool isLeftSide = cj < 25;

    random_device rd;
    mt19937 eng(rd());
    uniform_int_distribution<int> distr(2, 15);
    int border = distr(eng);
    if (ci < border || cj < border || ci >= 50 - border || cj >= 50 - border) {
        return base;
    }
    switch (direction) {
        case 0:
            if (isUpperSide) {
                return 0;
            } else {
                return base * base;
            }
        case 1:
            if (!isLeftSide) {
                return 0;
            } else {
                return base * base;
            }
        case 2:
            if (!isUpperSide) {
                return 0;
            } else {
                return base * base;
            }
        case 3:
            if (isLeftSide) {
                return 0;
            } else {
                return base * base;
            }
        default:
            return base;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    const vector<int> di = {-1, 0, 1, 0};
    const vector<int> dj = {0, 1, 0, -1};
    const vector<char> direction = {'U', 'R', 'D', 'L'};

    int si;
    cin >> si;
    int sj;
    cin >> sj;

    vector<vector<int>> tiles(50, vector<int>(50));
    vector<vector<int>> board(50, vector<int>(50));
    rep(i, 50) rep(j, 50) cin >> tiles.at(i).at(j);
    rep(i, 50) rep(j, 50) cin >> board.at(i).at(j);

    set<int> history = {};
    history.insert(tiles[si][sj]);
    string route;
    ll step = 1;

    int ci = si, cj = sj;

    while (true) {
        // label, direction, tile, nextI, nextJ
        vector<tuple<double, char, int, int, int>> list;

        int current_tile = tiles[ci][cj];

        rep(k, 4) {
            int next_i = ci + di[k];
            int next_j = cj + dj[k];

            if (next_i < 0 || next_i >= 50 || next_j < 0 || next_j >= 50) {
                continue;
            }

            int next_tile = tiles[next_i][next_j];

            if (current_tile != next_tile) {
                if (history.find(next_tile) == history.end()) {
                    double score = calc_score(k, ci, cj, board[next_i][next_j]);
                    list.emplace_back(score, direction[k], next_tile, next_i, next_j);
                }
            }
        }

        if (list.empty()) {
            break;
        } else {
            SORT_REVERSE(list);
            int label, tile, ni, nj;
            char next;
            tie(label, next, tile, ni, nj) = list.front();
            route += next;
            history.insert(tile);
            ci = ni;
            cj = nj;
            step++;
        }
    }
    cout << route << endl;
}
