#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int SIZE = 200005;
const int BLOCK = 200005;


class SegTree{
public:
  int v[SIZE*4];

  SegTree(){ 
    memset(v,0,sizeof(v));
  }
  
  int get(int node, int L, int R, int LQ, int RQ){
    if(R<LQ || RQ<L) return 0;
    if(LQ<=L && R<=RQ) return v[node];
    int s = get(node*2+1,L,(L+R)/2,LQ,RQ);
    int t = get(node*2+2,(L+R)/2+1,R,LQ,RQ);
    return s+t;
  }
  
  int update(int node, int L, int R, int Q, int chVal){
    if(R<Q || Q<L) return v[node];
    if(L==R) return v[node] = chVal;
    int s = update(node*2+1,L,(L+R)/2,Q,chVal);
    int t = update(node*2+2,(L+R)/2+1,R,Q,chVal);
    return v[node] = s+t;
  }
};


int row, col;
int nBlock, blockPos[BLOCK][2];

void read() {
    cin >> row >> col >> nBlock;
    for (int i = 0; i < nBlock; ++i) {
        cin >> blockPos[i][0] >> blockPos[i][1];
        --blockPos[i][0];
        --blockPos[i][1];
    }
}


void work() {
    static vector<int> row2col[SIZE], col2row[SIZE];
    for (int i = 0; i < SIZE; ++i) {
        row2col[i].clear();
        col2row[i].clear();
    }
    for (int i = 0; i < nBlock; ++i) {
        row2col[blockPos[i][0]].push_back(blockPos[i][1]);
        col2row[blockPos[i][1]].push_back(blockPos[i][0]);
    }
    for (int i = 0; i < SIZE; ++i) {
        sort(row2col[i].begin(), row2col[i].end());
        sort(col2row[i].begin(), col2row[i].end());
    }
    
    long long sum = 0;

    // Add horizontal line
    for (int r = 0; r < (col2row[0].size() > 0 ? col2row[0][0] : row); ++r) {
        sum += row2col[r].size() > 0 ? row2col[r][0] : col;
    }

    // Add vertical line
    static SegTree stree;
    stree = SegTree();
    for (int c = 0; c < (row2col[0].size() > 0 ? row2col[0][0] : col); ++c) {
        int until = col2row[c].size() > 0 ? col2row[c][0] - 1 : row - 1;
        if (until >= 0)
            sum += stree.get(0, 0, row - 1, 0, until);

        if (c == 0) {
            for (int r = (col2row[0].size() > 0 ? col2row[0][0] : row); r < row; ++r) {
                stree.update(0, 0, row - 1, r, 1);
            }
        } else {
            for (int i = 0; i < col2row[c].size(); ++i) {
                stree.update(0, 0, row - 1, col2row[c][i], 1);
            }
        }
    }

    cout << sum << endl;
}


int main() {
    read();
    work();
    return 0;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

string a, b, c;
ll na, nb, nc;
vector<ll> aa, bb, cc;
ll nmp[10];
inline ll getnum(char c) {
    if (nmp[0] == c) return 0;
    if (nmp[1] == c) return 1;
    if (nmp[2] == c) return 2;
    if (nmp[3] == c) return 3;
    if (nmp[4] == c) return 4;
    if (nmp[5] == c) return 5;
    if (nmp[6] == c) return 6;
    if (nmp[7] == c) return 7;
    if (nmp[8] == c) return 8;
    if (nmp[9] == c) return 9;
    return -1;
}
inline ll getchar(ll n) {
    return nmp[n];
}
void fail() {
    print("UNSOLVABLE");
    exit(0);
}
void success() {
    for (ll i = 0; i < na; i++) {
        print0(aa[na - i - 1]);
    }
    print();
    for (ll i = 0; i < nb; i++) {
        print0(bb[nb - i - 1]);
    }
    print();
    for (ll i = 0; i < nc; i++) {
        print0(cc[nc - i - 1]);
    }
    print();
    exit(0);
}
void rec(ll i, ll kuri, ll abc, vector<ll> &nvec, string &ts) {
    if (abc == 0 || abc == 1) {
        ll nn = ts.size();
        if (i >= nn) {
            rec(i, kuri, abc + 1, bb, b);
            return;
        }
        char d = ts[i];
        if (getnum(d) < 0) {
            for (ll j = 0; j < 10; j++) {
                if (nmp[j] >= 0) continue;
                nmp[j] = d;
                nvec.push_back(getnum(d));
                rec(i, kuri, abc + 1, bb, b);
                nvec.pop_back();
                nmp[j] = -1;
            }
        } else {
            nvec.push_back(getnum(d));
            rec(i, kuri, abc + 1, bb, b);
            nvec.pop_back();
        }
    }
    if (abc == 2) {
        char d = c[i];
        ll cv = kuri;
        if (i < na) cv += aa[i];
        if (i < nb) cv += bb[i];
        ll nkuri = 0;
        if (cv >= 10) {
            nkuri = 1;
            cv -= 10;
        }
        bool change = false;
        if (getnum(d) < 0) {
            if (getchar(cv) >= 0) {
                return;
            }
            nmp[cv] = d;
            change = true;
        }
        if (getnum(d) != cv) {
            return;
        }

        if (i == nc - 1) {
            cc.push_back(cv);
            if (!(nkuri > 0 || aa.back() == 0 || bb.back() == 0 || cc.back() == 0)) {
                success();
            }
            cc.pop_back();
        } else {
            cc.push_back(cv);
            rec(i + 1, nkuri, 0, aa, a);
            cc.pop_back();
        }

        if (change) {
            nmp[cv] = -1;
        }
    }
}
int main() {
    cin >> a >> b >> c;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    na = a.size();
    nb = b.size();
    nc = c.size();
    if (na > nc || nb > nc || nc > max(na, nb) + 1) {
        fail();
    }
    {
        set<char> chars;
        for (char x : a) {
            chars.insert(x);
        }
        for (char x : b) {
            chars.insert(x);
        }
        for (char x : c) {
            chars.insert(x);
        }
        if (chars.size() > 10) {
            fail();
        }
    }
    for(ll i=0;i<10;i++){
      nmp[i]=-1;
    }
    rec(0, 0, 0, aa, a);
    fail();
}
