#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=(1e4+9+2000+2),M=(N+1e4)*2,INF=1e9;
int n,m,g,S,T,tot=-1,sum;
int h[N],dis[N],cur[N],ver[M],nxt[M],f[M];
int Q[N],hh,tt,a[N];

inline void add(int x,int y,int z)
{
	ver[++tot]=y,nxt[tot]=h[x],h[x]=tot,f[tot]=z;
	ver[++tot]=x,nxt[tot]=h[y],h[y]=tot,f[tot]=0;
}

inline bool bfs()
{
	memset(dis,-1,sizeof dis);
	hh=tt=0;
	Q[0]=S,dis[S]=0,cur[S]=h[S];
	while(hh<=tt)
	{
		int u=Q[hh++];
		for(int i=h[u];~i;i=nxt[i])
		{
			int v=ver[i];
			if(dis[v]==-1&&f[i])
			{
				dis[v]=dis[u]+1;
				cur[v]=h[v];
				if(v==T) return true;
				Q[++tt]=v;
			}
		}
	}
	return false;
}

int dfs(int u,int lim)
{
	if(u==T) return lim;
	int flow=0;
	for(int i=cur[u];~i&&flow<lim;i=nxt[i])
	{
		int v=ver[i];
		if(dis[v]==dis[u]+1&&f[i])
		{
			int t=dfs(v,min(f[i],lim-flow));
			if(!t) dis[v]=-1;
			f[i]-=t,f[i^1]+=t,flow+=t;
		}
	}
	return flow;
}

int dinic()
{
	int res=0;
	while(bfs()) res+=dfs(S,INF);
	return res;
}
int main()
{
	memset(h,-1,sizeof h);
	scanf("%d%d%d",&n,&m,&g);
	S=0,T=n+m+1;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		if(a[i]==0) add(S,i,x);
		else add(i,T,x);
	}
	for(int i=1;i<=m;i++)
	{
		int op,w,k,p;
		bool flag;
		scanf("%d%d%d",&op,&w,&k);
		sum+=w;
		while(k--)
		{
			scanf("%d",&p);
			if(op==0) add(i+n,p,INF);
			else add(p,i+n,INF);
		}
		scanf("%d",&flag);
		if(flag) w+=g;
		if(op==0) add(S,i+n,w);
		else add(i+n,T,w);
	}
	printf("%d",sum-dinic());
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int N=(1e5+9+2000+2)*2,M=(N+1e4),INF=1e9;
int n,m,g,S,T,tot=-1,sum;
int h[N],dis[N],cur[N],ver[M],nxt[M],f[M];
int Q[N],hh,tt,a[N];

inline void add(int x,int y,int z)
{
	ver[++tot]=y,nxt[tot]=h[x],h[x]=tot,f[tot]=z;
	ver[++tot]=x,nxt[tot]=h[y],h[y]=tot,f[tot]=0;
}

inline bool bfs()
{
	memset(dis,-1,sizeof dis);
	hh=tt=0;
	Q[0]=S,dis[S]=0,cur[S]=h[S];
	while(hh<=tt)
	{
		int u=Q[hh++];
		for(int i=h[u];~i;i=nxt[i])
		{
			int v=ver[i];
			if(dis[v]==-1&&f[i])
			{
				dis[v]=dis[u]+1;
				cur[v]=h[v];
				if(v==T) return true;
				Q[++tt]=v;
			}
		}
	}
	return false;
}

int dfs(int u,int lim)
{
	if(u==T) return lim;
	int flow=0;
	for(int i=cur[u];~i&&flow<lim;i=nxt[i])
	{
		int v=ver[i];
		if(dis[v]==dis[u]+1&&f[i])
		{
			int t=dfs(v,min(f[i],lim-flow));
			if(!t) dis[v]=-1;
			f[i]-=t,f[i^1]+=t,flow+=t;
		}
	}
	return flow;
}

int dinic()
{
	int res=0;
	while(bfs()) res+=dfs(S,INF);
	return res;
}
signed main()
{
	memset(h,-1,sizeof h);
	scanf("%lld%lld%lld",&n,&m,&g);
	S=0,T=n+m+1;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%lld",&x);
		if(a[i]==0) add(S,i,x);
		else add(i,T,x);
	}
	for(int i=1;i<=m;i++)
	{
		int op,w,k,p;
		int flag;
		scanf("%lld%lld%lld",&op,&w,&k);
		sum+=w;
		while(k--)
		{
			scanf("%lld",&p);
			if(op==0) add(i+n,p,INF);
			else add(p,i+n,INF);
		}
		scanf("%lld",&flag);
		if(flag) w+=g;
		if(op==0) add(S,i+n,w);
		else add(i+n,T,w);
	}
	printf("%lld",sum-dinic());
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=40005;
int head[maxn],t[maxn<<3],ne[maxn<<3],sap[maxn<<3],num;
const int inf=1<<30;
inline void addedge(int x,int y,int z){
	ne[++num]=head[x];head[x]=num;t[num]=y;sap[num]=z;
	ne[++num]=head[y];head[y]=num;t[num]=x;sap[num]=0;
}
int cnt[maxn],cur[maxn],his[maxn],in[maxn],out[maxn],S,T,SS,TT,edge[maxn],pre[maxn],d[maxn];
inline int isap(){
	rep(i,1,T)cur[i]=head[i],d[i]=0,cnt[i]=0;cnt[0]=T;int i=S,aug=inf,ans=0,jl,minnum;
	while(d[S]<T){
		his[i]=aug;bool flag=0;for(int j=cur[i];j!=-1;j=ne[j])if(sap[j]&&d[t[j]]+1==d[i]){
			flag=1;aug=min(aug,sap[j]);pre[t[j]]=i;edge[i]=j;cur[i]=j;i=t[j];
			if(i==T){ans+=aug;
				while(i!=S){i=pre[i];sap[edge[i]]-=aug;sap[edge[i]^1]+=aug;}aug=inf;
			}break;
		}if(flag)continue;minnum=T;forE(j,i)if(sap[j]&&d[t[j]]<minnum)minnum=d[t[j]],jl=j;
		if(--cnt[d[i]]==0)return ans;cnt[d[i]=minnum+1]++;cur[i]=jl;
		if(i!=S){i=pre[i];aug=his[i];}
	}return ans;
}
int v[maxn],sex[maxn],n,m,g,nd[maxn];
int main(){
//	judge();
	read(n);read(m);read(g);
	rep(i,1,n)read(sex[i]);
	rep(i,1,n)read(v[i]);
	S=n+m+1;T=n+m+2;
	rep(i,1,T)head[i]=-1;
	rep(i,1,n)
		if(sex[i])
			addedge(i,T,v[i]);
		else
			addedge(S,i,v[i]);
	int res=0;
	rep(i,1,m){
		int w,c,k;
		read(c);read(w);read(k);res+=w;
		rep(i,1,k)read(nd[i]);
		int v;read(v);v*=g;
		if(c)
			addedge(i+n,T,v+w);
		else
			addedge(S,i+n,v+w);
		rep(j,1,k)addedge(i+n,nd[j],inf),addedge(nd[j],i+n,inf);
	}res-=isap();
	cout<<res;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=40005;
int head[maxn],t[maxn<<3],ne[maxn<<3],sap[maxn<<3],num;
const int inf=1<<30;
inline void addedge(int x,int y,int z){
	ne[++num]=head[x];head[x]=num;t[num]=y;sap[num]=z;
	ne[++num]=head[y];head[y]=num;t[num]=x;sap[num]=0;
}
int cnt[maxn],cur[maxn],his[maxn],in[maxn],out[maxn],S,T,SS,TT,edge[maxn],pre[maxn],d[maxn];
inline int isap(){
	rep(i,1,T)cur[i]=head[i],d[i]=0,cnt[i]=0;cnt[0]=T;int i=S,aug=inf,ans=0,jl,minnum;
	while(d[S]<T){
		his[i]=aug;bool flag=0;for(int j=cur[i];j!=-1;j=ne[j])if(sap[j]&&d[t[j]]+1==d[i]){
			flag=1;aug=min(aug,sap[j]);pre[t[j]]=i;edge[i]=j;cur[i]=j;i=t[j];
			if(i==T){ans+=aug;
				while(i!=S){i=pre[i];sap[edge[i]]-=aug;sap[edge[i]^1]+=aug;}aug=inf;
			}break;
		}if(flag)continue;minnum=T;forE(j,i)if(sap[j]&&d[t[j]]<minnum)minnum=d[t[j]],jl=j;
		if(--cnt[d[i]]==0)return ans;cnt[d[i]=minnum+1]++;cur[i]=jl;
		if(i!=S){i=pre[i];aug=his[i];}
	}return ans;
}
int v[maxn],sex[maxn],n,m,g,nd[maxn];
int main(){
//	judge();
	read(n);read(m);read(g);num=1;
	rep(i,1,n)read(sex[i]);
	rep(i,1,n)read(v[i]);
	S=n+m+1;T=n+m+2;
	rep(i,1,T)head[i]=-1;
	rep(i,1,n)
		if(sex[i])
			addedge(i,T,v[i]);
		else
			addedge(S,i,v[i]);
	int res=0;
	rep(i,1,m){
		int w,c,k;
		read(c);read(w);read(k);res+=w;
		rep(i,1,k)read(nd[i]);
		int v;read(v);v*=g;
		if(c)
			addedge(i+n,T,v+w);
		else
			addedge(S,i+n,v+w);
		rep(j,1,k)
			if(!c)
				addedge(i+n,nd[j],inf);
			else
				addedge(nd[j],i+n,inf);
	}res-=isap();
	cout<<res;
	return 0;
}


#include<bits/stdc++.h>
#define	INF	0x3f3f3f3f
#define	LL	long long
#define	MAXN	10010
#define	MAXM	2010
#define MAXD	10010
using namespace std;
int n, m, g, v[MAXN], s[MAXN], fri[MAXM], d[MAXM][11], w[MAXM], k[MAXM], opt[MAXM];
int S, T, dis[MAXD], ans, tim;
struct info{int v, c; unsigned r;};
unsigned cur[MAXD];
vector <info> a[MAXD];

template <typename T> void chkmin(T &x, T y){x = min(x, y);}
template <typename T> void chkmax(T &x, T y){x = max(x, y);}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

void add(int u, int v, int c){
	a[u].push_back((info){v, c, (unsigned)a[v].size()});
	a[v].push_back((info){u, 0, (unsigned)a[u].size() - 1});
}

int bfs(){
	static int q[MAXD], l = 0, r = 0;
	for (int i = 0; i <= r; ++i)
		dis[q[i]] = 0;
	q[l = r = 0] = S, dis[S] = 1;
	while (l <= r){
		int pos = q[l++];
		for (unsigned i = 0, si = a[pos].size(); i < si; ++i){
			int to = a[pos][i].v, cap = a[pos][i].c;
			if (!dis[to] && cap) dis[to] = dis[pos] + 1, q[++r] = to;
		}
	}
	return (dis[T] != 0);
}

int dinic(int pos, int lim){
	if (pos == T) return lim;
	int used = 0, tmp;
	for (unsigned &i = cur[pos], si = a[pos].size(); i < si; ++i){
		int to = a[pos][i].v, cap = a[pos][i].c, re = a[pos][i].r;
		if (cap && dis[to] == dis[pos] + 1 && (tmp = dinic(to, min(lim - used, cap)))){
			a[pos][i].c -= tmp, a[to][re].c += tmp, used += tmp;
			if (used == lim) return used;
		}
	}
	return used;
}

int main(){
	read(n), read(m), read(g);
	for (int i = 1; i <= n; ++i)
		read(s[i]);
	for (int i = 1; i <= n; ++i)
		read(v[i]);
	for (int i = 1; i <= m; ++i){
		read(opt[i]), read(w[i]), read(k[i]);
		ans += w[i];
		for (int j = 1; j <= k[i]; ++j)
			read(d[i][j]);
		read(fri[i]);
	}
	S = 0, T = tim = n + 1;
	for (int i = 1; i <= n; ++i){
		if (s[i] == 0) add(S, i, 0), add(i, T, v[i]);
		else add(S, i, v[i]), add(i, T, 0);
	}
	for (int i = 1; i <= m; ++i){
		if (opt[i] == 1) {
			++tim;
			add(S, tim, w[i] + fri[i] * g);
			for (int j = 1; j <= k[i]; ++j)
				add(tim, d[i][j], INF);
		} else {
			++tim;
			add(tim, T, w[i] + fri[i] * g);
			for (int j = 1; j <= k[i]; ++j)
				add(d[i][j], tim, INF);
		}
	}
	while (bfs()){
		memset(cur, 0, sizeof(cur));
		ans -= dinic(S, INF);
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
#define	INF	0x3f3f3f3f
#define	LL	long long
#define	MAXN	10010
#define	MAXM	2010
#define MAXD	20010
using namespace std;
int n, m, g, v[MAXN], s[MAXN], fri[MAXM], d[MAXM][11], w[MAXM], k[MAXM], opt[MAXM];
int S, T, dis[MAXD], ans, tim;
struct info{int v, c; unsigned r;};
unsigned cur[MAXD];
vector <info> a[MAXD];

template <typename T> void chkmin(T &x, T y){x = min(x, y);}
template <typename T> void chkmax(T &x, T y){x = max(x, y);}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

void add(int u, int v, int c){
	a[u].push_back((info){v, c, (unsigned)a[v].size()});
	a[v].push_back((info){u, 0, (unsigned)a[u].size() - 1});
}

int bfs(){
	static int q[MAXD], l = 0, r = 0;
	for (int i = 0; i <= r; ++i)
		dis[q[i]] = 0;
	q[l = r = 0] = S, dis[S] = 1;
	while (l <= r){
		int pos = q[l++];
		for (unsigned i = 0, si = a[pos].size(); i < si; ++i){
			int to = a[pos][i].v, cap = a[pos][i].c;
			if (!dis[to] && cap) dis[to] = dis[pos] + 1, q[++r] = to;
		}
	}
	return (dis[T] != 0);
}

int dinic(int pos, int lim){
	if (pos == T) return lim;
	int used = 0, tmp;
	for (unsigned &i = cur[pos], si = a[pos].size(); i < si; ++i){
		int to = a[pos][i].v, cap = a[pos][i].c, re = a[pos][i].r;
		if (cap && dis[to] == dis[pos] + 1 && (tmp = dinic(to, min(lim - used, cap)))){
			a[pos][i].c -= tmp, a[to][re].c += tmp, used += tmp;
			if (used == lim) return used;
		}
	}
	return used;
}

int main(){
	read(n), read(m), read(g);
	for (int i = 1; i <= n; ++i)
		read(s[i]);
	for (int i = 1; i <= n; ++i)
		read(v[i]);
	for (int i = 1; i <= m; ++i){
		read(opt[i]), read(w[i]), read(k[i]);
		ans += w[i];
		for (int j = 1; j <= k[i]; ++j)
			read(d[i][j]);
		read(fri[i]);
	}
	S = 0, T = tim = n + 1;
	for (int i = 1; i <= n; ++i){
		if (s[i] == 0) add(S, i, 0), add(i, T, v[i]);
		else add(S, i, v[i]), add(i, T, 0);
	}
	for (int i = 1; i <= m; ++i){
		if (opt[i] == 1) {
			++tim;
			add(S, tim, w[i] + fri[i] * g);
			for (int j = 1; j <= k[i]; ++j)
				add(tim, d[i][j], INF);
		} else {
			++tim;
			add(tim, T, w[i] + fri[i] * g);
			for (int j = 1; j <= k[i]; ++j)
				add(d[i][j], tim, INF);
		}
	}
	while (bfs()){
		memset(cur, 0, sizeof(cur));
		ans -= dinic(S, INF);
	}
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=30000;
const int INF=1<<30;
int n,m,G,s,t,ans;
int level[maxn],a[maxn];
struct node {
	int from,to,ca,flow,fid,tid;
};
vector<node> g[maxn];
queue<int> q;
int get_left(int a,node e) {
	if (a==e.from)
		return e.ca-e.flow;
	return e.flow;
}
int get_other(int a,node e) {
	if (a==e.from)
		return e.to;
	return e.from;
}
void add_edge(int a,int b,int c) {
	node e;
	e.from=a; e.to=b;
	e.fid=g[a].size();
	e.tid=g[b].size();
	e.ca=c; e.flow=0;
	g[a].push_back(e);
	g[b].push_back(e);
}
void add_flow(int a,node &e,int f) {
	if (a==e.from)
		e.flow+=f;
	else e.flow-=f;
}
bool bfs() {
	q=queue<int>();
	memset(level,-1,sizeof(level));
	q.push(s);
	level[s]=0;
	while (!q.empty()) {
		int a=q.front();
		q.pop();
		for (int i=0;i<g[a].size();i++) {
			node e=g[a][i];
			int b=get_other(a,e);
			if (get_left(a,e)>0&&level[b]==-1) {
				level[b]=level[a]+1;
				q.push(b);
			}
		}
	}
	return level[t]!=-1;
}
int dfs(int x,int rest) {
	if (x==t) return rest;
	int used=0;
	for (int i=0;i<g[x].size();i++) {
		node e=g[x][i];
		int y=get_other(x,e);
		if (get_left(x,e)>0&&level[y]==level[x]+1) {
			int tflow=dfs(y,min(get_left(x,e),rest-used));
			used+=tflow;
			add_flow(x,g[e.from][e.fid],tflow);
			add_flow(x,g[e.to][e.tid],tflow);
		}
	}
	if (!used) level[x]=-1;
	return used;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m); read(G);
	for (int i=1;i<=n;i++) read(a[i]);
	s=n+m+1; t=n+m+2; int x,y,op,w,sum=0;
	for (int i=1;i<=n;i++) {
		read(x);
		if (a[i]) add_edge(i,t,0),add_edge(s,i,x);
		else add_edge(i,t,x),add_edge(s,i,0);
	}
	for (int i=1;i<=m;i++) {
		read(op); read(w);
		sum+=w; read(y);
		while (y--) {
			read(x);
			if (op) add_edge(i+n,x,INF);
			else add_edge(x,i+n,INF);
		} read(y); w+=y*G;
		if (op) add_edge(s,i+n,w);
		else add_edge(i+n,t,w);
	}
	while (bfs())
		ans+=dfs(s,INF);
	printf("%d\n",sum-ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e4+5,M=1e5+5;
const ll INF=0x3fffffff;
int n,m,g,st,ed,te=1;
int a[N],dep[M],vv[M<<1],pre[M<<1],tail[M],now[M];
ll Ans,Flow,ww[M<<1];//dinic

inline void add(int u,int v,int w)
{
	++te;vv[te]=v;ww[te]=(ll)w;pre[te]=tail[u];tail[u]=te;
}

bool bfs()
{
	memset(dep,0,sizeof(dep));

	dep[st]=1;now[st]=tail[st];

	vector<int>q;
	q.push_back(st);

	int l=0;
	while(l<q.size())
	{

		int u=q[l++];
		for(int i=tail[u];i;i=pre[i])
		{
			int v=vv[i];ll w=ww[i];

			if(w==0||dep[v]) continue;

			dep[v]=dep[u]+1;
			now[v]=tail[v];
			q.push_back(v);

			if(v==ed) return 1;
		}
	}
	return 0;
}

ll dfs(int u,ll val)
{
	if(u==ed) return val;

	int &i=now[u];
	ll rest=val;
	for(;i&&rest;i=pre[i])
	{
		int v=vv[i];ll w=ww[i];

		if(dep[v]==dep[u]+1&&w)
		{
			ll d=dfs(v,min(rest,w));

			if(!d) dep[v]=0;

			rest-=d;ww[i]-=d;ww[i^1]+=d;
		}
	}
	return val-rest;
}
int main()
{
	scanf("%d %d %d",&n,&m,&g);
	st=0;
	ed=n+m+1;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1,x;i<=n;++i)
	{
		scanf("%d",&x);
		if(a[i]) add(i,ed,x),add(ed,i,0);
		else add(st,i,x),add(i,st,0);
	}
	for(int i=1,id,w,k,x;i<=m;++i)
	{
		scanf("%d %d %d",&id,&w,&k);Ans+=w;
		if(id) for(int j=1;j<=k;++j) scanf("%d",&x),add(x,n+i,INF),add(n+i,x,0);
		else for(int j=1;j<=k;++j) scanf("%d",&x),add(x,n+i,0),add(n+i,x,INF);
		scanf("%d",&x);
		if(id) add(n+i,ed,w+x*g),add(ed,n+i,0);
		else add(st,n+i,w+x*g),add(n+i,st,0);
	}

	while(bfs())
	{
		while(ll d=dfs(st,INF))	Flow+=d;
	}

	printf("%lld",Ans-Flow);
}


#include<bits/stdc++.h>
#define next nxt
using namespace std;
int read(){
	int c=0,nx,sign=1;
	do{
		nx=getchar()-'0';
		if(nx=='-'-'0')
			sign=-1;
	}while(nx<0 or nx>9);
	while(nx>=0 and nx<=9){
		c=c*10+nx;
		nx=getchar()-'0';
	}
	return sign*c;
}
const int  N=2e4+10,M=2e6+20;
int head[N],next[M],ver[M],edge[M];
inline void addEdge(int u,int v,int e){
	static int now=1;
	++now;
	next[now]=head[u];
	ver[now]=v;
	head[u]=now;
	edge[now]=e;
	++now;
	swap(u,v);
	next[now]=head[u];
	ver[now]=v;
	head[u]=now;
	edge[now]=0;
}
int n,m,s,t,maxflow;
int d[N];
int bfs(){
	memset(d,0,sizeof(d));
	queue<int>q;
	d[s]=1;
	q.push(s);
	while(q.size()){
		int u=q.front(),v;
		q.pop();
		for(int i=head[u];i;i=next[i]){
			v=ver[i];
			if(edge[i] and !d[v]){
				q.push(v);
				d[v]=d[u]+1;
				if(v==t)
					return 1;
			}
		}
	}
	return 0;
}
int dinic(int u,int flow){
	if(u==t)
		return flow;
	int rest=flow,k;
	for(int i=head[u];i and rest;i=next[i]){
		int v=ver[i];
		if(edge[i] and d[v]==d[u]+1){
			k=dinic(v,min(rest,edge[i]));
			if(!k)
				d[v]=0;
			edge[i]-=k;
			edge[i^1]+=k;
			rest-=k;
		}
	}
	return flow-rest;
}
int a[N],ans;
int main(){
	int n=read(),m=read(),g=read();
	s=n+m+1,t=s+1;
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++){
		if(a[i])
			addEdge(s,i,read());
		else
			addEdge(i,t,read());
	}
	for(int i=1;i<=m;i++){
		int op=read(),w=read(),k=read();
		ans+=w;
		for(int j=1;j<=k;j++){
			if(op)
				addEdge(i+n,read(),1e9);
			else
				addEdge(read(),i+n,1e9);
		}
		if(read())
			w+=g;
		if(op)
			addEdge(s,i+n,w);
		else
			addEdge(i+n,t,w);
	}
	int flow;
	while(bfs())
		while(flow=dinic(s,INT_MAX))
			maxflow+=flow;
	printf("%d\n",ans-maxflow);
}


#include <bits/stdc++.h>
using namespace std;
#define id(x,y) (x-1)*m+y
const int maxn=8e5+10;
const int fi=1e4;
const int inf=1e9;
int n,m,s,t,sumn,dis[maxn],x;
struct edge{
	int to,nxt,flow;
}d[maxn]; int head[maxn],cnt=1;
void add(int u,int v,int flow){
	d[++cnt]=(edge){v,head[u],flow},head[u]=cnt;
	d[++cnt]=(edge){u,head[v],0},head[v]=cnt;
}
bool bfs()
{
	for(int i=0;i<=t;i++)	dis[i]=0;
	dis[s]=1;
	queue<int>q; q.push( s );
	while( !q.empty() )
	{
		int u=q.front(); q.pop();
		for(int i=head[u];i;i=d[i].nxt )
		{
			int v=d[i].to;
			if( d[i].flow&&dis[v]==0 )
			{
				dis[v]=dis[u]+1;
				if( v==t )	return true;
				q.push( v );
			}
		}
	}
	return false;
}
int dinic(int u,int flow)
{
	if( u==t )	return flow;
	int res=flow;
	for(int i=head[u];i&&res;i=d[i].nxt )
	{
		int v=d[i].to;
		if( dis[v]==dis[u]+1&&d[i].flow)
		{
			int temp=dinic(v,min(res,d[i].flow) );
			if( temp==0 )	dis[v]=0;
			res-=temp;
			d[i].flow-=temp;
			d[i^1].flow+=temp;
		}
	}
	return flow-res;
}
int g,a[maxn],v[maxn];
int main()
{
	cin >> n >> m >> g;
	//s表示1,t表示0
	s=0,t=10009; int r=n;
	for(int i=1;i<=n;i++ )	cin >> a[i];
	for(int i=1;i<=n;i++ )
	{
		cin >> v[i];
		if( a[i] )	add(s,i,v[i]),add(i,t,0 );
		else	add(s,i,0),add(i,t,v[i] );
	}
	while( m-- )
	{
		int ok,li,shu,one; cin >> ok >> li >> shu;
		r++;
		if( ok )	add(s,r,li);
		else	add(r,t,li);
		sumn+=li;
		for(int i=1;i<=shu;i++)
		{
			int x; cin >> x;//编号x的人必须是ok
			if( ok==1 )
				add(r,x,inf);
			else
				add(x,r,inf);
		}
		cin >> one;
		if( one )
		{
			if( ok )	add(s,r,g);
			else	add(r,t,g);
		}
	}
	int ans=0;
	while( bfs() )	ans+=dinic(s,inf);
	cout << sumn-ans;
}


//对最小割应当更熟练
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
const int maxn = 1008611;
int n,m,s,t,tot,sum,g;
struct node
{
	int to,next,w;
}e[1000086];
int head[maxn],d[maxn],cur[maxn],a[maxn],b[maxn];
queue <int> q;
void add(int x,int y,int w)
{
	e[tot].to = y;
	e[tot].w = w;
	e[tot].next = head[x];
	head[x] = tot++;

	e[tot].to = x;
	e[tot].w = 0;
	e[tot].next = head[y];
	head[y] = tot++;
}
bool bfs()
{
	memset(d,-1,sizeof(d));
	q.push(s);
	d[s] = 0;
	while(q.size())
	{
		int x = q.front();
		q.pop();
		for(int i = head[x]; i != -1; i = e[i].next)
		{
			int y = e[i].to;
			int w = e[i].w;
			if(w && d[y] == -1)
			{
				d[y] = d[x] + 1;
				q.push(y);
			}
		}
	}
	return d[t] != -1;
}
int dfs(int x,int flow)
{
	if(x == t) return flow;
	int delta = flow;
	for(int &i = cur[x]; i != -1; i = e[i].next)
	{
		int y = e[i].to;
		int w = e[i].w;
		if(w && d[y] == d[x] + 1)
		{
			int dist = dfs(y,min(w,delta));
			e[i].w -= dist;
			e[i ^ 1].w += dist;
			delta -= dist;
			if(!delta) break;
		}
	}
	return flow - delta;
}
int dinic()
{
	int ans = 0;
	while(bfs())
	{
		for(int i = 0; i <= t; i++) cur[i] = head[i];
		ans += dfs(s,0x3f3f3f3f);
	}
	return ans;
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d%d",&n,&m,&g);
	s = 0,t = maxn - 1;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i = 1; i <= n; i++)
	{
		scanf("%d",&b[i]);
		if(a[i] == 0) add(s,i,b[i]);
		if(a[i] == 1) add(i,t,b[i]);
	}
	for(int i = 1; i <= m; i++)
	{
		int op,op2,val,k;
		scanf("%d%d%d",&op,&val,&k);
		sum += val;
		for(int j = 1; j <= k; j++)
		{
			int x;
			scanf("%d",&x);
			if(op) add(x,n + i,0x3f3f3f3f);
			else add(n + i,x,0x3f3f3f3f);
		}
		scanf("%d",&op2);
		if(!op) add(s,n + i,val + op2 * g);
		else add(n + i,t,val + op2 * g);
	}
	printf("%d\n",sum - dinic());
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e4+5,M=3e4+5;
const ll INF=0x3fffffff;
int n,m,g,st,ed,te=1;
int a[N],vv[M<<1],pre[M<<1],tail[M],now[M];
ll Ans,Flow,dep[M],ww[M<<1];//dinic

inline void add(int u,int v,int w)
{
	++te;vv[te]=v;ww[te]=(ll)w;pre[te]=tail[u];tail[u]=te;
}

bool bfs()
{
	memset(dep,0,sizeof(dep));

	dep[st]=1;now[st]=tail[st];

	vector<int>q;
	q.push_back(st);

	int l=0;
	while(l<q.size())
	{

		int u=q[l++];
		for(int i=tail[u];i;i=pre[i])
		{
			int v=vv[i];ll w=ww[i];

			if(w==0||dep[v]) continue;

			dep[v]=dep[u]+1;
			now[v]=tail[v];
			q.push_back(v);

			if(v==ed) return 1;
		}
	}
	return 0;
}

ll dfs(int u,ll val)
{
	if(u==ed) return val;

	int &i=now[u];
	ll rest=val;
	for(;i&&rest;i=pre[i])
	{
		int v=vv[i];ll w=ww[i];

		if(dep[v]==dep[u]+1&&w)
		{
			ll d=dfs(v,min(rest,w));

			if(!d) dep[v]=0;

			rest-=d;ww[i]-=d;ww[i^1]+=d;
		}
	}
	return val-rest;
}
int main()
{
	scanf("%d %d %d",&n,&m,&g);
	st=0;
	ed=n+m+1;
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1,x;i<=n;++i)
	{
		scanf("%d",&x);
		if(a[i]) add(i,ed,x),add(ed,i,0);
		else add(st,i,x),add(i,st,0);
	}
	for(int i=1,id,w,k,x;i<=m;++i)
	{
		scanf("%d %d %d",&id,&w,&k);Ans+=w;
		if(id) for(int j=1;j<=k;++j) scanf("%d",&x),add(x,n+i,INF),add(n+i,x,0);
		else for(int j=1;j<=k;++j) scanf("%d",&x),add(x,n+i,0),add(n+i,x,INF);
		scanf("%d",&x);
		if(id) add(n+i,ed,w+x*g),add(ed,n+i,0);
		else add(st,n+i,w+x*g),add(n+i,st,0);
	}

	while(bfs())
	{
		while(ll d=dfs(st,INF))	Flow+=d;
	}

	printf("%lld",Ans-Flow);
}


#include<map>
#include<queue>
#include<cmath>
#include<ctime>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=ans*10+ch-'0',ch=getchar();
	return ans*fh;
}
const int maxn=1e5+100,maxm=2e6+100,inf=0x7fffffff;
int head[maxn],nex[maxm],v[maxm],w[maxm],num=1,cur[maxn],cc[maxn];
int n,m,g,c[maxn],b[maxn],s,t,ans;
queue<int>q;
inline void add(int x,int y,int z){
	v[++num]=y;
	w[num]=z;
	nex[num]=head[x];
	head[x]=num;
	v[++num]=x;
	w[num]=0;
	nex[num]=head[y];
	head[y]=num;
}
inline bool bfs(){
	memset(cc,0,sizeof(cc));
	cc[s]=1,q.push(s);
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=head[x];i;i=nex[i])
			if(w[i]&&!cc[v[i]])
				cc[v[i]]=cc[x]+1,q.push(v[i]);
	}
	return cc[t];
}
int dfs(int x,int ll){
	if(x==t) return ll;
	for(int i=head[x];i;i=nex[i])
		if(w[i]&&cc[v[i]]==cc[x]+1){
			int pp=dfs(v[i],ll>w[i]?w[i]:ll);
			if(pp){
				w[i]-=pp,w[i^1]+=pp;
				return pp;
			}
		}
	return 0;
}
inline int dinic(){
	int maxl=0,ll;
	while(bfs()){
		memcpy(cur,head,sizeof(cur));
		while(ll=dfs(s,inf)) maxl+=ll;
	}
	return maxl;
}
int main(){
//	freopen(".in","r",stdin);
	n=read(),m=read(),g=read(),s=0,t=n+m+1;
	for(int i=1;i<=n;i++) c[i]=read();
	for(int i=1;i<=n;i++){
		int x=read();
		if(c[i]) add(s,i,x);
		else add(i,t,x);
	}
	for(int i=1;i<=m;i++){
		int ms=read(),z=read(),k=read();
		ans+=z;
		for(int j=1;j<=k;j++)
			b[j]=read();
		z+=read()*g;
		for(int j=1;j<=k;j++)
			if(ms) add(n+i,b[j],inf);
			else add(b[j],n+i,inf);
		if(ms) add(s,n+i,z);
		else add(n+i,t,z);
	}
	printf("%d\n",ans-dinic());
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long inf=(long long)1e17;
const int N=50010;
const int G=300010;
long long sum;
int n,m,tot,l;
int cur[N],dep[N],head[N];
int nc[N];
struct EDGE
{
	int v,nxt;
	long long val;
}g[G];
void intl()
{
	tot=0;
	memset(head,-1,sizeof(head));
}
void add(int u,int v,long long w)
{
	g[tot].v=v;
	g[tot].nxt=head[u];
	g[tot].val=w;
	head[u]=tot++;
}
void addedge(int u,int v,long long w)
{
	add(u,v,w);
	add(v,u,0);
}
bool bfs(int s,int t)
{
	memset(dep,0,sizeof(dep));
	queue<int> Q;
	Q.push(s);
	dep[s]=1;
	cur[s]=head[s];
	while(!Q.empty())
	{
		s=Q.front();
		Q.pop();
		for(int i=head[s],v;~i;i=g[i].nxt)
			if(g[i].val>0&&!dep[v=g[i].v])
			{
				dep[v]=dep[s]+1;
				cur[v]=head[v];
				if(v==t) return true;
				Q.push(v);
			}
	}
	return false;
}
long long dfs(int s,int t,long long flow)
{
	if(s==t||flow<=0) return flow;
	long long res=flow;
	for(int i=cur[s],v;~i;i=g[i].nxt)
	{
		cur[s]=i;
		if(g[i].val>0&&dep[v=g[i].v]==dep[s]+1)
		{
			long long tmp=dfs(v,t,min(res,g[i].val));
			res-=tmp;
			g[i].val-=tmp;
			g[i^1].val+=tmp;
			if(res<=0) break;
		}
	}
	return flow-res;
}
long long maxflow(int s,int t)
{
	long long ans=0;
	while(bfs(s,t))
		ans+=dfs(s,t,inf);
	return ans;
}
int main()
{
	intl();
	scanf("%d%d%d",&n,&m,&l);
	int s=0,t=n+1,num=n+2;
	for(int i=1;i<=n;i++)
		scanf("%d",&nc[i]);
	for(int i=1;i<=n;i++)
	{
		long long V;
		scanf("%d",&V);
		if(nc[i]) addedge(i,t,V);
		else addedge(s,i,V);
	}
	for(int i=1;i<=m;i++)
	{
		int go,wk,nm,y;
		scanf("%d%d%d",&go,&wk,&nm);
		sum+=wk;
		num++;
		if(go) addedge(num,t,wk);
		else addedge(s,num,wk);
		for(int j=1;j<=nm;j++)
		{
			int x;
			scanf("%d",&x);
			if(go) addedge(x,num,inf);
			else addedge(num,x,inf);
		}
		scanf("%d",&y);
		if(y)
		{
			num++;
			if(go)
			{
				addedge(num-1,num,inf);
				addedge(num,t,l);
			}
			else
			{
				addedge(num,num-1,inf);
				addedge(s,num,l);
			}
		}
	}
	printf("%lld",sum-maxflow(s,t));
	return 0;
}


#include<stdio.h>
#include<queue>
#define inf 1000000000
using namespace std;
const int maxn=10005,maxm=200005;
int i,j,k,g,m,n,s,t,e,flg,ans,sum;
int start[maxn],to[maxm],then[maxm],worth[maxm],rev[maxm],dep[maxn],vis[maxn],a[maxn],v[maxn];
queue<int>q;
inline int min(int a,int b){
	return a<b? a:b;
}
inline void add(int x,int y,int z,int r){
	then[++e]=start[x],start[x]=e,to[e]=y,worth[e]=z,rev[e]=r;
}
inline void addedge(int x,int y,int z){
	add(x,y,z,e+2),add(y,x,0,e);
}
void bfs(){
	while(!q.empty())
		q.pop();
	for(int i=1;i<=n;i++)
		dep[i]=inf,vis[i]=0;
	dep[s]=0;
	q.push(s);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		vis[x]=0;
		for(int i=start[x];i;i=then[i]){
			int y=to[i];
			if(worth[i]&&dep[y]>dep[x]+1){
				dep[y]=dep[x]+1;
				if(vis[y]==0){
					vis[y]=1;
					q.push(y);
				}
			}
		}
	}
}
int dfs(int x,int flw){
	if(x==t){
		flg=1,ans+=flw;
		return flw;
	}
	int rest=flw;
	for(int i=start[x];i;i=then[i]){
		int y=to[i];
		if(worth[i]&&dep[y]==dep[x]+1){
			int newflw=dfs(y,min(rest,worth[i]));
			if(newflw>0){
				rest-=newflw;
				worth[i]-=newflw,worth[rev[i]]+=newflw;
				if(rest==0)
					break;
			}
			else dep[y]=0;
		}
	}
	return flw-rest;
}
int Dinic(){
	ans=0;
	while(1){
		bfs();
		if(dep[t]==inf)
			break;
		flg=1;
		while(flg){
			flg=0;
			dfs(s,inf);
		}
	}
	return ans;
}
int main(){
	scanf("%d%d%d",&n,&m,&g);
	s=n+m+1,t=n+m+2;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		scanf("%d",&v[i]);
	for(i=1;i<=n;i++){
		if(a[i]==0)
			addedge(s,i,v[i]);
		else addedge(i,t,v[i]);
	}
	for(i=1;i<=m;i++){
		int opt,w,k,x,y;
		scanf("%d%d%d",&opt,&w,&k);
		sum+=w;
		for(j=1;j<=k;j++){
			scanf("%d",&x);
			if(opt==0)
				addedge(n+i,x,inf);
			else addedge(x,n+i,inf);
		}
		scanf("%d",&y);
		if(opt==0)
			addedge(s,n+i,w+y*g);
		else addedge(n+i,t,w+y*g);
	}
	n=t;
	printf("%d\n",sum-Dinic());
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename T>
inline void read(T &num) {
	num = 0; bool w = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') w = 0; c = getchar(); }
	while(isdigit(c)) { num = num*10+c-'0';; c = getchar(); }
	num = w ? num : -num;
}

const int N = 2e4 + 10, M = 2e5 + 10, INF = 0x3f3f3f3f;
int n, g, m, s, t, edg[M], to[M], H[N], nxt[M], dep[N];
int val[N], col[N], tot=1, ans, Max;

inline void add(int u, int v, int w) {
	to[++tot] = v, edg[tot] = w, nxt[tot] = H[u], H[u] = tot;
	to[++tot] = u, edg[tot] = 0, nxt[tot] = H[v], H[v] = tot;
}

inline bool bfs() {
	for(int i = s; i <= t; i++) dep[i] = 0;
	queue<int> q; dep[s] = 1; q.push(s);
	while(q.size()) {
		int x = q.front(); q.pop();
		for(int i = H[x]; i; i = nxt[i]) {
			if(!edg[i] || dep[to[i]]) continue;
			dep[to[i]] = dep[x] + 1; q.push(to[i]);
			if(to[i] == t) return 1;
		}
	}
	return 0;
}

inline int dfs(int x, int flow) {
	if(x == t) return flow;
	int k, ret = flow;
	for(int i = H[x]; i && ret; i = nxt[i]) {
		if(dep[to[i]]!=dep[x]+1 || !edg[i]) continue;
		k = dfs(to[i], min(ret, edg[i]));
		if(!k) dep[to[i]] = 0;
		edg[i] -= k;
		edg[i^1] += k;
		ret -= k;
	}
	return flow - ret;
}

signed main() {
	read(n), read(m), read(g); s = 0; t = n + m + 1;
	for(int i = 1; i <= n; i++) read(col[i]);
	for(int i = 1; i <= n; i++) read(val[i]);
	for(int i = 1; i <= n; i++) {
		if(col[i]) add(s, i, val[i]);
		else add(i, t, val[i]);
	}
	for(int i = 1, opt1, w, k, opt2; i <= m; i++) {
		read(opt1); read(w); read(k); ans += w;
		for(int j = 1, to; j <= k; j++) { read(to);
			if(opt1) add(i + n, to, INF);
			else add(to, i + n, INF);
		}
		read(opt2);
		if(opt1) add(s, i+n, w + g*opt2);
		else add(i+n, t, w + g*opt2);
	}
	while(bfs()) ans -= dfs(s, INF);
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	PI c[k];
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++){
		cin>>b[i].ff>>b[i].ss;
		c[i]={abs(a[i].ff-b[i].ff)+abs(a[i].ss-b[i].ss),i};
	}
	sort(c,c+k);
	int visit[k]={0};
	string ans="";
	for(int ii=0;ii<k;ii++){
		int i=c[ii].ss;
		if(visit[i])continue;

		if(a[i].ff<b[i].ff){
			int diff = b[i].ff-a[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ff<n)
						a[j].ff++;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)
				ans+='D';
		}
		else{
			int diff = a[i].ff-b[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ff>1)
						a[j].ff --;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)ans+='U';
		}

		if(a[i].ss>b[i].ss){
			int diff = a[i].ss - b[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[i].ss>1)
						a[j].ss --;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)ans+='L';
		}
		else{
			int diff = b[i].ss - a[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ss < m)
						a[j].ss ++;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)ans+='R';
		}
	}

	if(ans.size() > 2*n*m)
		cout<<-1<<endl;
	else
		cout<<ans.size()<<endl<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	PI c[k];
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++){
		cin>>b[i].ff>>b[i].ss;
	}
	int visit[k]={0};
	string ans="";
	for(int i=0;i<k;i++){
		if(visit[i])continue;

		if(a[i].ff<b[i].ff){
			int diff = b[i].ff-a[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ff<n)
						a[j].ff++;
					if(a[j]==b[j]){
						//cout<<j<<endl;
						visit[j]=1;
					}
				}
				ans+='D';
			}
		}
		else{
			int diff = a[i].ff-b[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ff>1)
						a[j].ff --;
					if(a[j]==b[j]){
						//cout<<j<<endl;
						visit[j]=1;
					}
				}
				ans+='U';
			}
		}

		if(a[i].ss>b[i].ss){
			int diff = a[i].ss - b[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[i].ss>1)
						a[j].ss --;
					if(a[j]==b[j]){
						visit[j]=1;
						//cout<<j<<endl;
					}
				}
				ans+='L';
			}
		}
		else{
			int diff = b[i].ss - a[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					if(a[j].ss < m)
						a[j].ss ++;
					if(a[j]==b[j]){
						//cout<<j<<endl;
						visit[j]=1;
					}
				}
				ans+='R';
			}
		}
	}
	if(ans.size() > 2*n*m)
		cout<<-1<<endl;
	else
		cout<<ans.size()<<endl<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++)
		cin>>b[i].ff>>b[i].ss;
	string ans="";

	for(int i=1;i<n;i++)
		ans+='L';
	for(int i=1;i<m;i++)
		ans+='U';
	for(int i=0;i<k;i++){
		if(i%2==0){
			for(int i=1;i<n;i++)
				ans+='R';
		}
		else{
			for(int i=1;i<n;i++)
				ans+='L';
		}
		ans+='D';
	}
	cout<<ans.size()<<endl<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;
const int N=1e3+1;
bool okk(int x,int y){
	for(int i=0;i<k;i++){
		if(a[i].ff+x<0 or a[i].ff+x>n)
			return false;
		if(a[i].ss+y<0 or a[i].ss+y>m)
			return false;
	}
	for(int i=0;i<k;i++){
		a[i].ff+=x;
		a[i].ss+=y;
	}
	return true;
}

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++)
		cin>>b[i].ff>>b[i].ss;

	bool ok =true;
	int r=0,l=0,d=0,u=0;
	for(int i=0;i<k;i++){
		if(a[i].ff<=b[i].ff)
			d=max(d,b[i].ff-a[i].ff);
		else
			u = max(u,a[i].ff-b[i].ff);

		if(a[i].ss<b[i].ss)
			r = max(r,b[i].ss-a[i].ss);
		else
			l = max(l,a[i].ss-b[i].ss);
	}

	//cout<<l<<" "<<r<<" "<<d<<" "<<u<<endl;
	string ans="";
	/*if(l+r+d+u <= 2*n*m){

		while(l>0 or r>0 or d>0 or u>0){
			if(l>0 && okk(0,-1)){
				ans+='L';
				l--;
			}
			else if(r>0 && okk(0,1)){
				ans+='R';
				r--;
			}
			else if(u>0 && okk(-1,0)){
				ans+='U';
				u--;
			}
			else if(d>0 && okk(1,0)){
				ans+='D';
				d--;
			}
			else{
				ok =false;
				break;
			}
		}
	}
	else
		ok=false;
	cout<<ans<<endl;*/
	if(l+r+u+d <=2*n*m){
		cout<<l+r+u+d<<endl;
		while(l--)cout<<'L';
		while(r--)cout<<'R';
		while(u--)cout<<'U';
		while(d--)cout<<'D';
		cout<<endl;
	}
	else
		cout<<-1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++)
		cin>>b[i].ff>>b[i].ss;

	int visit[k]={0};
	string ans="";
	for(int i=0;i<k;i++){
		if(visit[i])continue;

		if(a[i].ff<b[i].ff){
			int diff = b[i].ff-a[i].ff;
				for(int j=0;j<k;j++){
					a[j].ff+=diff;
			}
			while(diff--)
				ans+='D';
		}
		else{
			int diff = a[i].ff-b[i].ff;
			for(int j=0;j<k;j++)
				a[j].ff -= diff;
			while(diff--)ans+='U';
		}

		if(a[i].ss>b[i].ss){
			int diff = a[i].ss - b[i].ss;
			for(int j=0;j<k;j++)
				a[j].ss-=diff;
			while(diff--)ans+='L';
		}
		else{
			int diff = b[i].ss - a[i].ss;
			for(int j=0;j<k;j++)
				a[j].ss+=diff;
			while(diff--)ans+='R';
		}
	}

	if(ans.size() > 2*n*m)
		cout<<-1<<endl;
	else
		cout<<ans.size()<<endl<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define PI pair<int,int>
#define ff first
#define ss second
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)

vector<PI>a,b;
int n,m,k;

int32_t main() {
	boost;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE

	cin>>n>>m>>k;
	a.resize(k);
	b.resize(k);
	for(int i=0;i<k;i++)
		cin>>a[i].ff>>a[i].ss;
	for(int i=0;i<k;i++)
		cin>>b[i].ff>>b[i].ss;

	int visit[k]={0};
	string ans="";
	for(int i=0;i<k;i++){
		if(visit[i])continue;

		if(a[i].ff<b[i].ff){
			int diff = b[i].ff-a[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					a[j].ff++;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)
				ans+='D';
		}
		else{
			int diff = a[i].ff-b[i].ff;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					a[j].ff --;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}
			while(diff--)ans+='U';
		}

		if(a[i].ss>b[i].ss){
			int diff = a[i].ss - b[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					a[j].ss --;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}while(diff--)ans+='L';
		}
		else{
			int diff = b[i].ss - a[i].ss;
			for(int l=0;l<diff;l++){
				for(int j=0;j<k;j++){
					a[j].ss ++;
					if(a[j]==b[j])
						visit[j]=1;
				}
			}while(diff--)ans+='R';
		}
	}

	if(ans.size() > 2*n*m)
		cout<<-1<<endl;
	else
		cout<<ans.size()<<endl<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1 + n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n-1;i++)cout<<"D";
return 0;}
if(n==1){
    cout<<m-1 + m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    for(int i=0;i<m-1;i++)cout<<"R";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = (m-1)*(n) + m-1 +n-1 +n;
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m-1;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1 + n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n-1;i++)cout<<"D";
return 0;}
if(n==1){
    cout<<m-1 + m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    for(int i=0;i<m-1;i++)cout<<"R";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = m*(n) + m-1 +n-1 +n;
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];

int ans = m*(n+1) + n +n;
cout<<ans<<endl;
for(int i=0;i<m;i++)cout<<"L";
for(int i=0;i<n;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,k;

int chect[100];
for(int i=0;i<200;i++)chect[i/10]=1;
cin>>n>>m>>k;
pair<int,int> s[k];
pair<int,int> f[k];
for(int i=0;i<k;i++)
{
    int x,y;
    cin>>x>>y;
    s[i].ff=x;
    s[i].ss=y;
}
for(int i=0;i<k;i++)
{
    cin>>f[i].ff>>f[i].ss;
}
string ans="";
for(int i=0;i<m-1;i++)
{
    ans+='L';
}
for(int i=0;i<n-1;i++)
{
    ans+='U';
}
int ok=1;
for(int i=0;i<n;i++)
{
    for(int j=0;j<m-1;j++)
    {if(ok)
        ans+='R';
        else
            ans+='L';

    }   ok=1-ok;
    ans+='D';
}
if(ans.size()>2*n*m)
{
    cout<<-1<<endl;
    return 0;
}
cout<<ans.size()<<endl;
cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
return 0;}
if(n==1){
    cout<<m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = m*(n) + m-1 +n-1 +n;
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[1000][2] , en[10000][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1 + n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n-1;i++)cout<<"D";
return 0;}
if(n==1){
    cout<<m-1 + m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    for(int i=0;i<m-1;i++)cout<<"R";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = (m-1)*(n) + m-1 +n-1 +n;
if(ans>2*n*m)
{
    cout<<-1<<endl;
    return 0;
}
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m-1;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1 + n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n-1;i++)cout<<"D";
return 0;}
if(n==1){
    cout<<m-1 + m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    for(int i=0;i<m-1;i++)cout<<"R";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = (m-1)*(n) + m-1 +n-1 +n;
if(ans>2*n*m)
{
    cout<<-1<<endl;
    return 0;
}
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m-1;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];

int ans = m +n + n*m;
cout<<ans<<endl;
for(int i=0;i<m;i++)cout<<"L";
for(int i=0;i<n;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 2000
#define ll long long

int main(){
//int t;
//cin>>t;
//while(t--)
    {

 int n , m , k;
    cin>>n>>m>>k;

int st[n][2] , en[n][2];

for(int i=0;i<k;i++){
    cin>>st[i][0]>>st[i][1];
}
for(int i=0;i<k;i++){
    cin>>en[i][0]>>en[i][1];
}
int dp[n][m];
if(n==1 && m==1){
    cout<<"1\n U";
    return 0;
}
if(m==1){cout<<n-1 + n-1<<endl;
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n-1;i++)cout<<"D";
return 0;}
if(n==1){
    cout<<m-1 + m-1<<endl;
    for(int i=0;i<m-1;i++)cout<<"L";
    for(int i=0;i<m-1;i++)cout<<"R";
    return 0;
}

if(n==2 && m==2){
    cout<<" 4 \n LURD";
    return 0;
}

if(n==2){
    cout<<(m-1 + 1+ m-1 + 1 +m-1)<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
cout<<"U";
for(int i=0;i<m-1;i++)cout<<"R";
cout<<"D";
for(int i=0;i<m-1;i++)cout<<"L";
return 0;
}
if(m==2){
    cout<<(n-1 + n + n-1)<<endl;
    for(int i=0;i<n-1;i++)cout<<"U";
cout<<"L";
for(int i=0;i<n-1;i++)cout<<"D";
cout<<"R";
for(int i=0;i<n-1;i++)cout<<"U";
return 0;
}

int ans = (m-1)*(n) + m-1 +n-1 +n;
if(ans.size()>2*n*m)
{
    cout<<-1<<endl;
    return 0;
}
cout<<ans<<endl;
for(int i=0;i<m-1;i++)cout<<"L";
for(int i=0;i<n-1;i++)cout<<"U";
for(int i=0;i<n;i++){
    for(int j=0;j<m-1;j++){
            if(i%2==0)
        cout<<"R";
    else cout<<"L";
    }
    cout<<"D";
}

    }
    return 0;
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d",&n,&m,&k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char>ans;
    for (int i = 0; i < k; i++) {

        int upcount = v1[i].ff.ff-1;
        if(upcount>0){
            for(int j=0;j<upcount;j++){
                cnt++;
                ans.EB('U');
            }
            for(int j=0;j<k;j++){
                int tmpcount = max(0,min(upcount,v1[j].ff.ff-1));
                v1[j].ff.ff-=tmpcount;
            }
        }
        int leftcount = v1[i].ff.ss - 1;
        if (leftcount > 0) {
            for (int j = 0; j < leftcount; j++) {
                cnt++;
                ans.EB('L');
            }
            for (int j = 0; j < k; j++) {
                int tmpcount = max(0, min(leftcount, v1[j].ff.ss - 1));
                v1[j].ff.ss -= tmpcount;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }

    printf("%d\n",cnt);
    if(cnt!=-1){
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    sort(all(v1), [](pair<pii, pii>& a, pair<pii, pii>& b) {
        return (abs(a.ff.ff - a.ss.ff) + abs(a.ff.ss - a.ff.ss)) > (abs(b.ff.ff - b.ss.ff) + abs(b.ff.ss - b.ss.ss));
    });
    vector<bool> done(k, 0);
    int cnt = 0;
    string ans = "";
    for (int i = 0; i < k; i++) {
        //sobaike up
        //sobaike left
        if (done[i])
            continue;
        //up
        while (v1[i].ff.ff > 1) {
            cnt++;
            ans += "U";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ff - 1 < 1)
                    continue;
                v1[j].ff.ff--;
                if (v1[j].ff == MP(1, 1))
                    done[j] = 1;
            }
        }
        //left
        while (v1[i].ff.ss > 1) {
            cnt++;
            ans += "L";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss - 1 < 1)
                    continue;
                v1[j].ff.ss--;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ans += "D";
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans += "L";
            else
                ans += "R";
        }
    }
    if (cnt > 2 * n * m) {
        cnt = -1;
    }
    cout << cnt << "\n"
         << (cnt == -1 ? "" : ans) << "\n";
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d",&n,&m,&k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char>ans;
    for (int i = 0; i < k; i++) {

        int upcount = v1[i].ff.ff-1;
        if(upcount>0){
            for(int j=0;j<upcount;j++){
                cnt++;
                ans.EB('U');
            }
            for(int j=0;j<k;j++){
                int tmpcount = max(0,min(upcount,v1[j].ff.ff-1));
                v1[j].ff.ff-=tmpcount;
            }
        }
        int leftcount = v1[i].ff.ss - 1;
        if (leftcount > 0) {
            for (int j = 0; j < leftcount; j++) {
                cnt++;
                ans.EB('L');
            }
            for (int j = 0; j < k; j++) {
                int tmpcount = max(0, min(leftcount, v1[j].ff.ss - 1));
                v1[j].ff.ss -= tmpcount;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }
    if (cnt > 2 * n * m) {
        cnt = -1;
    }
    printf("%d\n",cnt);
    if(cnt!=-1){
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d",&n,&m,&k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char>ans;
    for(int i=0;i<n-1;i++)cnt++,ans.EB('U');
    for(int i=0;i<m-1;i++)cnt++,ans.EB('L');
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }

    printf("%d\n",cnt);
    if(cnt!=-1){
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d",&n,&m,&k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char>ans;
    for(int i=0;i<n-1;i++)cnt++,ans.EB('U');
    for(int i=0;i<m-1;i++)cnt++,ans.EB('L');
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m-1; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }

    printf("%d\n",cnt);
    if(cnt!=-1){
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d",&n,&m,&k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char>ans;
    for(int i=0;i<n;i++)cnt++,ans.EB('U');
    for(int i=0;i<m;i++)cnt++,ans.EB('L');
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }

    printf("%d\n",cnt);
    if(cnt!=-1){
        for(int i=0;i<ans.size();i++){
            printf("%c",ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

int main() {
    int n,m,k;
    vector< pair<pii,pii> >v1;
    pii x;
    cin>>n>>m>>k;
    for(int i=0;i<k;i++){
        scanf("%d %d",&x.ff,&x.ss);
        v1.EB(MP(x,x));
    }
    for(int i=0;i<k;i++){
        scanf("%d %d",&x.ff,&x.ss);
        v1[i].ss = x;
    }
    sort(all(v1),[](pair<pii,pii>&a,pair<pii,pii>&b){
        return (abs(a.ff.ff-a.ss.ff)+abs(a.ff.ss-a.ff.ss))>(abs(b.ff.ff-b.ss.ff)+abs(b.ff.ss-b.ss.ss));
    });
    vector<bool>done(k,0);
    int cnt = 0;
    string ans = "";
    for(int i=0;i<k;i++){
        //sobaike up/down
        //sobaike left/right
        if(done[i])continue;
        //up
        while (v1[i].ff.ff>v1[i].ss.ff)
        {
            cnt++;
            ans+="U";
            for(int j=0;j<k;j++){
                if(done[j])continue;
                if(v1[j].ff.ff-1<1)continue;
                v1[j].ff.ff--;
                if(v1[j].ff==v1[j].ss)done[j]=1;
            }
        }
        //down
        while (v1[i].ff.ff<v1[i].ss.ff)
        {
            cnt++;
            ans+="D";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ff + 1 >n)
                    continue;
                v1[j].ff.ff++;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        //left
        while (v1[i].ff.ss>v1[i].ss.ss)
        {
            cnt++;
            ans+="L";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss - 1 <1)
                    continue;
                v1[j].ff.ss--;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        //right
        while (v1[i].ff.ss<v1[i].ss.ss)
        {
            cnt++;
            ans += "R";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss + 1 > m)
                    continue;
                v1[j].ff.ss++;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        if(cnt>2*n*m){
            cnt = -1;
            break;
        }
    }
    cout<<cnt<<"\n";
    if(cnt!=-1)cout<<ans<<"\n";
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

int main() {
    int n,m,k;
    vector< pair<pii,pii> >v1;
    pii x;
    cin>>n>>m>>k;
    for(int i=0;i<k;i++){
        scanf("%d %d",&x.ff,&x.ss);
        v1.EB(MP(x,x));
    }
    for(int i=0;i<k;i++){
        scanf("%d %d",&x.ff,&x.ss);
        v1[i].ss = x;
    }
    sort(all(v1),[](pair<pii,pii>&a,pair<pii,pii>&b){
        return (abs(a.ff.ff-a.ss.ff)+abs(a.ff.ss-a.ff.ss))<(abs(b.ff.ff-b.ss.ff)+abs(b.ff.ss-b.ss.ss));
    });
    vector<bool>done(k,0);
    int cnt = 0;
    string ans = "";
    for(int i=0;i<k;i++){
        //sobaike up/down
        //sobaike left/right
        if(done[i])continue;
        //up
        while (v1[i].ff.ff>v1[i].ss.ff)
        {
            cnt++;
            ans+="U";
            for(int j=0;j<k;j++){
                if(done[j])continue;
                if(v1[j].ff.ff-1<1)continue;
                v1[j].ff.ff--;
                if(v1[j].ff==v1[j].ss)done[j]=1;
            }
        }
        //down
        while (v1[i].ff.ff<v1[i].ss.ff)
        {
            cnt++;
            ans+="D";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ff + 1 >n)
                    continue;
                v1[j].ff.ff++;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        //left
        while (v1[i].ff.ss>v1[i].ss.ss)
        {
            cnt++;
            ans+="L";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss - 1 <1)
                    continue;
                v1[j].ff.ss--;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        //right
        while (v1[i].ff.ss<v1[i].ss.ss)
        {
            cnt++;
            ans += "R";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss + 1 > m)
                    continue;
                v1[j].ff.ss++;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
        if(cnt>2*n*m){
            cnt = -1;
            break;
        }
    }
    cout<<cnt<<"\n";
    if(cnt!=-1)cout<<ans<<"\n";
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    sort(all(v1), [](pair<pii, pii>& a, pair<pii, pii>& b) {
        return (abs(a.ff.ff - a.ss.ff) + abs(a.ff.ss - a.ff.ss)) > (abs(b.ff.ff - b.ss.ff) + abs(b.ff.ss - b.ss.ss));
    });
    vector<bool> done(k, 0);
    int cnt = 0;
    string ans = "";
    for (int i = 0; i < k; i++) {
        //sobaike up
        //sobaike left
        if (done[i])
            continue;
        //up
        while (v1[i].ff.ff > 1) {
            cnt++;
            ans += "U";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ff - 1 < 1)
                    continue;
                v1[j].ff.ff--;
                if (v1[j].ff == MP(1, 1))
                    done[j] = 1;
            }
        }
        //left
        while (v1[i].ff.ss > 1) {
            cnt++;
            ans += "L";
            for (int j = 0; j < k; j++) {
                if (done[j])
                    continue;
                if (v1[j].ff.ss - 1 < 1)
                    continue;
                v1[j].ff.ss--;
                if (v1[j].ff == v1[j].ss)
                    done[j] = 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ans += "D";
            cnt++;
        }
        for (int j = 0; j < m; j++) {
            cnt++;
            if (i % 2)
                ans += "L";
            else
                ans += "R";
        }
    }
    if (cnt > 2 * n * m) {
        cnt = -1;
    }
    cout << cnt << "\n"
         << (cnt == -1 ? "" : ans) << "\n";
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int range = powl(10, i) - 1;
        int cnt = 0;
        for (int j = 0; j <= range; j++) {
            string tmp = to_string(j);
            reverse(all(tmp));
            while (tmp.size() < i) {
                tmp += "0";
            }
            reverse(all(tmp));
            int prev = -1;
            int pcnt = 0;
            for (int k = 0; k < tmp.size(); k++) {
                if (prev != (tmp[k] - '0')) {
                    prev = tmp[k] - '0';
                    pcnt = 1;
                } else {
                    pcnt++;
                }
                if (pcnt == i)
                    cnt++;
            }
        }
        cout<<cnt<<"\n";
    }
}


#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;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

void solveC() {
    int n, m, k;
    vector<pair<pii, pii>> v1;
    pii x;
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1.EB(MP(x, x));
    }
    for (int i = 0; i < k; i++) {
        scanf("%d %d", &x.ff, &x.ss);
        v1[i].ss = x;
    }
    int cnt = 0;
    vector<char> ans;
    for (int i = 0; i < k; i++) {
        int upcount = v1[i].ff.ff - 1;
        if (upcount > 0) {
            for (int j = 0; j < upcount; j++) {
                cnt++;
                ans.EB('U');
            }
            for (int j = 0; j < k; j++) {
                int tmpcount = max(0, min(upcount, v1[j].ff.ff - 1));
                v1[j].ff.ff -= tmpcount;
            }
        }
        int leftcount = v1[i].ff.ss - 1;
        if (leftcount > 0) {
            for (int j = 0; j < leftcount; j++) {
                cnt++;
                ans.EB('L');
            }
            for (int j = 0; j < k; j++) {
                int tmpcount = max(0, min(leftcount, v1[j].ff.ss - 1));
                v1[j].ff.ss -= tmpcount;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (i) {
            ans.EB('D');
            cnt++;
        }
        for (int j = 0; j < m-1; j++) {
            cnt++;
            if (i % 2)
                ans.EB('L');
            else
                ans.EB('R');
        }
    }
    if (cnt > 2 * n * m) {
        cnt = -1;
    }
    printf("%d\n", cnt);
    if (cnt != -1) {
        for (int i = 0; i < ans.size(); i++) {
            printf("%c", ans[i]);
        }
    }
}

int main() {
    solveC();
    // int n;
    // cin >> n;
    // for (int i = 1; i <= n; i++) {
    //     int range = powl(10, i) - 1;
    //     int cnt = 0;
    //     for (int j = 0; j <= range; j++) {
    //         string tmp = to_string(j);
    //         reverse(all(tmp));
    //         while (tmp.size() < i) {
    //             tmp += "0";
    //         }
    //         reverse(all(tmp));
    //         int prev = -1;
    //         int pcnt = 0;
    //         for (int k = 0; k < tmp.size(); k++) {
    //             if (prev != (tmp[k] - '0')) {
    //                 prev = tmp[k] - '0';
    //                 pcnt = 1;
    //             } else {
    //                 pcnt++;
    //             }
    //             if (pcnt == i)
    //                 cnt++;
    //         }
    //     }
    //     cout<<cnt<<"\n";
    // }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){
	string s;
int n,m;cin>>n>>m;
int k;cin>>k;
int cnt=0;
vector<pii>v(205,0);
for(int i=0;i<k;i++){
cin>>v[i].ff>>v[i].ss;

}
vector<pii>vv(205,0);
fo(i,0,k){
    cin>>vv[i].ff>>vv[i].ss;
}
fo(i,0,k){
    int x=vv[i].ff-v[i].ff;
    int y=vv[i].ss-v[i].ss;
    if(x<0){

        for(int i=0;i<abs(x);i++){
            // cout<<"U";
           s.pb('U');
        }
        for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff<0)v[j].ff=0;
        }
    }
    else{

        for(int i=0;i<x;i++){
            // cout<<"D";
            s.pb('D');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ff+=x;
        	if(v[j].ff>n)v[j].ff=n;
        }
    }
    	cnt+=abs(x);
    if(y<0){
        for(int i=0;i<abs(y);i++){
            // cout<<"L";
            s.pb('L');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss<0)v[j].ss=0;
        }
    }else{
        for(int i=0;i<y;i++){
            // cout<<"R";
            s.pb('R');
        }
         for(int j=i+1;j<k;j++){
        	v[j].ss+=y;
        	if(v[j].ss>m)v[j].ss=m;
        }
    }
    cnt+=abs(y);
    // if(i==0){
    // 	for(int i=1;i<k;i++)cout<<v[i].ff<<" "<<v[i].ss<<endl;
    // }

}
cout<<cnt<<endl;
cout<<s<<endl;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){

int n,m,k;cin>>n>>m>>k;
for(int i=0;i<2*k;i++){
    int x;int y;cin>>x>>y;

}

cout<<n+m+n*m-3<<endl;
for(int i=1;i<m;i++)cout<<"L";
fo(i,1,n)cout<<"U";
for(int i=1;i<=m;i++){
    if(i&1){
        for(int j=1;j<n;j++)cout<<"D";
        if(i!=m)
        cout<<"R";
    }
    else{

        for(int j=1;j<n;j++)cout<<"U";
        if(i!=m)
        cout<<"R";

    }

}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
const int mx=1e5;

int32_t main(){

int n,m,k;cin>>n>>m>>k;
for(int i=0;i<2*k;i++){
    int x;int y;cin>>x>>y;

}

cout<<n+m+n*m-3<<endl;
for(int i=1;i<m;i++)cout<<"L";
fo(i,1,n)cout<<"U";
for(int i=1;i<=m;i++){
    if(i&1){
        for(int j=1;j<m;j++)cout<<"D";
        if(i!=m)
        cout<<"R";
    }
    else{

        for(int j=1;j<m;j++)cout<<"U";
        if(i!=m)
        cout<<"R";

    }

}

}