#include <bits/stdc++.h>
using namespace std;
#define lc rt << 1
#define rc rt << 1 | 1
#define int long long
typedef long long ll;
typedef pair<int, int> PII;
// #define ID(a, b) (((a) << 2) | (b))
const int INF = 0x3f3f3f3f3f3f3f3f;
// 除法真的是个危险的东西,因为除法可能是零
// 令千金我就笑纳了,我看夫人也是风韵犹存;
const double pi = acos(-1);
const int N = 1e6 + 10, inf = 0x3f3f3f3f, mod = 1e9 + 7;
int ji1=1,ji2=1,chu1=1,chu2=1,m,n;
int sign1=1,sign2=1;
int gcd(int a,int b)
{
return b ? gcd(b,a % b) : a;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("sushu.txt","w",stdout)
ji1=1,ji2=1,chu1=1,chu2=1;
cin>>n;
//cout<<2%0<<endl;
//cout<<gcd(5,2)<<endl;
for(int i=1;i<=n;i++){
int opr,x;
cin>>opr>>x;
if(opr==1){
ji1=abs(x*ji1);
}
else chu1=abs(x*chu1);
if(x<0) sign1*=-1;
}
int nx1=1,ny1=1;
//cout<<ji1<<' '<<chu1<<endl;
//cout<<gcd(4,4)<<endl;
int com=gcd(ji1,chu1)*1ll;
//cout<<com<<endl;
nx1=ji1/com; ny1=chu1/com;
cin>>m;
for(int i=1;i<=m;i++){
int opr,y;
cin>>opr>>y;
if(opr==1){
ji2=abs(y*ji2);
}
else chu2=abs(y*chu2);
if(y<0) sign2*=-1;
}
int nx2=1,ny2=1;
com=1;
int w=gcd(ji2,chu2)*1ll;
nx2=ji2/w; ny2=chu2/w;
if(nx1==nx2&&ny1==ny2&&sign1==sign2) cout<<"YES";
else cout<<"NO";
return 0;
}
/*
*/