#include<bits/stdc++.h>
using namespace std;
namespace IO{
template<typename T>inline void read(T &x){
x=0;int f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
x*=f;
}
const int BUF=1<<21;
char buf[BUF],tp,st[32];
int plen;
#define flush() fwrite(buf,1,plen,stdout),plen=0
inline void pc(char c){
buf[plen++]=c;
if(plen==BUF) flush();
}
template<typename T>inline void print(T x){
if(!x){pc(48);return;}
if(x<0) x=~x+1,pc('-');
while(x) st[++tp]=48^x%10,x/=10;
while(tp) pc(st[tp--]);
}
}
using namespace IO;
#define i128 __int128
const i128 mod=(i128)((i128)1000000000ll)*10000000000ll+51,two=2;
const int N=1e6+5;
int n,m,C,x;
i128 ans=1,ans1=1;
inline i128 ch(i128 x,i128 y){
if(x<y) swap(x,y);
i128 ans=0;
for(;y;y/=two,x=(x+x)%mod)
if(y%two==1) ans=(ans+x)%mod;
return ans;
}
inline i128 inv(i128 x){
i128 ans=1;
for(i128 y=mod-2;y;y/=two,x=ch(x,x))
if(y%two==1) ans=ch(ans,x);
return ans;
}
int main(){
read(n),read(m),read(C);
for(int i=1;i<=n;++i)
read(x),ans=ch(ans,x);
for(int i=1;i<=m;++i)
read(x),ans1=ch(ans1,x);
ans=ch(ans,inv(ans1));
if(C!=5){
bool fd=1;
for(i128 p=1;p<=10&&fd;++p)
for(int q=1;q<=10&&fd;++q)
if(__gcd(p,(i128)q)==1&&ch(p,inv(q))==ans){
print(p),pc(' '),print(q),pc('\n');
fd=0;
}
flush();
}else print(ans),pc(' '),pc(49),pc('\n');
flush();
return 0;
}
用逆元打的25分(第2个和第5个),但是只能过样例。模数取得 1019+51,大概是个质数。