#pragma warning(disable: 4786 )
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#include<map>
#include<utility>
#include<string>
#include<iostream>
#include<vector>
#include<set>

using namespace std;

char in[100000];

int main()
{

    char st[100];
    int n,now,then,a,b;

    while(scanf("%d",&n)==1)
    {
        gets(in);
        int ans=1;
        now=0;
        while(n--)
        {
            gets(in);
            sscanf(in,"%*c%d%*c%d%s",&a,&b,st);
            then=a*100+b;
            if(strcmp(st,"p.m.]:")==0)
            {
                then+=1200;
            }
            if( a==12)
            {
                then-=1200;
            }
            if(then<now)
                ans++;
            now=then;
        }

        printf("%d\n",ans);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)        for(int i=1;i<n;i++)
#define pi 3.1415926535897
/* lcm(a,b) , _gcd(a,b) , swap(a,b) , sort(a.begin(),a.end()) , *max_element(a.begin(),a.end()) , *min_element(a.begin(),a.end()) */

/* _builtin_popcount(x): This function is used to count the number of one’s */

/*__builtin_clz(x): This function is used to count the leading zeros of the integer. */

/*__builtin_ctz(x): This function is used to count the trailing zeros of the given integer */
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define mod 1000000007

bool isPrime(int n) {
	if (n == 1) {
		return false;
	}

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)
			return false;
	}
	return true;
}
// cout << fixed << setprecision(12) << ans << endl;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t ;
	cin >> t;

	while (t--) {
		int n;
		cin >> n;
		int a[n ];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int b[n + 1];
		for (int i = 0; i < n; i++) {
			cin >> b[i];
		}

		bool check = true;

		int i = 0;
		int j = 0;

		while (i < n) {
			if (a[i] == b[i]) {
				i++;
				continue;
			}
			int itr = i - 1;
			bool flag = false;
			int diff = b[i] - a[i];
			while (itr >= 0) {

				if (a[itr] == 0) {
					check = false;
					break;
				}
				else {
					int moves = diff / a[itr];
					// cout << moves << endl;
					if (moves > 0) {
						flag = true;
						break;
					}
				}
				itr--;
			}
			if (!flag) {
				check = false;
				break;
			}
			i++;

		}
		if (check) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)        for(int i=1;i<n;i++)
#define pi 3.1415926535897
/* lcm(a,b) , _gcd(a,b) , swap(a,b) , sort(a.begin(),a.end()) , *max_element(a.begin(),a.end()) , *min_element(a.begin(),a.end()) */

/* _builtin_popcount(x): This function is used to count the number of one’s */

/*__builtin_clz(x): This function is used to count the leading zeros of the integer. */

/*__builtin_ctz(x): This function is used to count the trailing zeros of the given integer */
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define mod 1000000007

bool isPrime(int n) {
	if (n == 1) {
		return false;
	}

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)
			return false;
	}
	return true;
}
// cout << fixed << setprecision(12) << ans << endl;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t ;
	cin >> t;

	while (t--) {
		int n;
		cin >> n;
		int a[n ];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int b[n + 1];
		for (int i = 0; i < n; i++) {
			cin >> b[i];
		}

		bool check = true;

		int i = n - 1;
		int j = 0;

		while (i >= 0) {
			if (a[i] == b[i]) {
				i--;
				continue;
			}
			int itr = i - 1;
			bool flag = false;
			int diff = b[i] - a[i];
			while (itr >= 0) {

				if (a[itr] == 0) {
					check = false;
					break;
				}
				else {
					int moves = diff / a[itr];
					// cout << moves << endl;
					if (moves > 0) {
						flag = true;
						break;
					}
				}
				itr--;
			}

			if (!flag) {
				check = false;
				break;
			}
			a[i] = b[i];
			i--;

		}
		if (check) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}

	}
}


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=-1,b=-1;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>brr[i];
        }
        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==-1)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==-1)
           {
               b=i;
           }
       }
      /*  for(int i=0;i<3;i++)
        {
            cout<<a[i]<<" ";
        }*/
        if(arr[0]!=brr[0])
        {
            cout<<"NO"<<"\n";
        }
        else
        {
          for(int i=0;i<n;i++)
        {
            if(arr[i]!=brr[i])
            {
                if(brr[i]<arr[i] && i<=a)
                {

                        f1=1;
                        break;

                }
                else if(brr[i]>arr[i] && i<=b)
                {

                        f1=1;
                        break;
                }

            }
        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
        }

        }
    }


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=n,b=n;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==n)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==n)
           {
               b=i;
           }
       }
          for(int i=0;i<n;i++)
        {    cin>>brr[i];

                if(brr[i]<arr[i] && i<=a)
                {

                        f1=1;

                }
                else if(brr[i]>arr[i] && i<=b)
                {

                        f1=1;

                }

        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }

        }
    }


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=n,b=n;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==n)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==n)
           {
               b=i;
           }
       }
          for(int i=0;i<n;i++)
        {    cin>>brr[i];

                if(brr[i]<arr[i] && i<=a)
                {

                        f1=1;
                        break;

                }
                else if(brr[i]>arr[i] && i<=b)
                {

                        f1=1;
                        break;

                }

        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }

        }
    }


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=-1,b=-1;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>brr[i];
        }
        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==-1)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==-1)
           {
               b=i;
           }
       }
      /*  for(int i=0;i<3;i++)
        {
            cout<<a[i]<<" ";
        }*/
        if(arr[0]!=brr[0])
        {
            cout<<"NO"<<"\n";
        }
        else
        {
          for(int i=0;i<n;i++)
        {
            if(arr[i]!=brr[i])
            {
                if(brr[i]<arr[i] && i<=a)
                {

                        f1=1;

                }
                else if(brr[i]>arr[i] && i<=b)
                {

                        f1=1;

                }

            }
        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
        }

        }
    }


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=-1,b=-1;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>brr[i];
        }
        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==-1)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==-1)
           {
               b=i;
           }
       }
      /*  for(int i=0;i<3;i++)
        {
            cout<<a[i]<<" ";
        }*/
        if(arr[0]!=brr[0])
        {
            cout<<"NO"<<"\n";
        }
        else
        {
          for(int i=n-1;i>0;i--)
        {
            if(arr[i]!=brr[i])
            {
                if(brr[i]<arr[i])
                {
                    if(a>=i)
                    {
                        f1=1;
                        break;
                    }
                }
                else
                {
                    if(b>=i)
                    {
                        f1=1;
                        break;
                    }
                }

            }
        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
        }

        }
    }


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n+1];

       /*  for(int i=-1;i<=1;i++)
        {
            cout<<a[i]<<" ";
        }*/

        int arr[n];
        int brr[n];
        int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>brr[i];
        }
        for(int i=0;i<n+1;i++)
        {
            a[i]=-1;
            cout<<a[i]<<" ";
        }
        cout<<"\n";
        for(int i=0;i<n;i++)
        {
            if(a[i] == -1)
            {
                a[arr[i]+1]=i;
            }
        }
        for(int i=0;i<n+1;i++)
        {
            cout<<a[i]<<" ";
        }
        if(arr[0]!=brr[0])
        {
            cout<<"NO"<<"\n";
        }
        else
        {
          for(int i=n-1;i>0;i++)
        {
            if(arr[i]!=brr[i])
            {
                if(brr[i]<arr[i])
                {
                    if(a[0]>=i)
                    {
                        f1=1;
                        break;
                    }
                }
                else
                {
                    if(a[arr[i]+1]>=i)
                    {
                        f1=1;
                        break;
                    }
                }

            }
        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
        }

    }
}


# include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        int brr[n];

            int a=-1,b=-1;
            int f1=0,f2=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>brr[i];
        }
        for(int i=0;i<n;i++)
        {
            if(arr[i]== -1 && a==-1)
            {
                a=i;
            }
        }
       for(int i=0;i<n;i++)
       {
           if(arr[i]==1 && b==-1)
           {
               b=i;
           }
       }
      /*  for(int i=0;i<3;i++)
        {
            cout<<a[i]<<" ";
        }*/
        if(arr[0]!=brr[0])
        {
            cout<<"NO"<<"\n";
        }
        else
        {
          for(int i=n-1;i>0;i--)
        {
            if(arr[i]!=brr[i])
            {
                if(brr[i]<arr[i] && i<=a)
                {

                        f1=1;
                        break;

                }
                else if(brr[i]>arr[i] && i<=b)
                {

                        f1=1;
                        break;
                }

            }
        }
        if(f1==0)
        {
            cout<<"YES"<<"\n";
        }
        else
        {
            cout<<"NO"<<"\n";
        }
        }

        }
    }


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

void update(bool& hasone, bool& hasminusone, int ai) {
	hasone = ai == 1;
	hasminusone = ai == -1;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone      = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	update(hasone, hasminusone, a[0]);
	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == 1 and a[i] == 1) {
				hasone = true;
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == -1 and a[i] == -1) {
				hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					hasone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					hasminusone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}
	}
	say("YES");
	return 0;

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

void update(bool& hasone, bool& hasminusone, int ai) {
	if (ai == 1) hasone = true;
	if (ai == -1) hasminusone = true;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone      = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	update(hasone, hasminusone, a[0]);
	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == 1 and a[i] == 1) {
				hasone = true;
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == -1 and a[i] == -1) {
				hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					hasone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					hasminusone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}
	}
	say("YES");
	return 0;

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

void update(bool& hasone, bool& hasminusone, int ai) {
	hasone = ai == 1;
	hasminusone = ai == -1;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone      = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	update(hasone, hasminusone, a[0]);
	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					hasone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					hasminusone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}
	}
	say("YES");
	return 0;

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	if (a[0] == 1) hasone = true;
	else if (a[0] == -1) hasminusone = true;

	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				if (a[i] == 1) hasone = true;
				else if (a[i] == -1) hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				if (a[i] == 1) hasone = true;
				else if (a[i] == -1) hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					hasone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					hasminusone = true;
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}

	}
	say("YES");

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

void update(bool& hasone, bool& hasminusone, int ai) {
	if (ai == 1) hasone = true;
	if (ai == -1) hasminusone = true;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone      = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	update(hasone, hasminusone, a[0]);
	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == 1 and a[i] == 1) {
				hasone = true;
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == -1 and a[i] == -1) {
				hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}
	}
	say("YES");
	return 0;

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include <iostream>
#include <vector>
using namespace std;

void say(string s) {
	cout << s << endl;
}

void update(bool& hasone, bool& hasminusone, int ai) {
	hasone = ai == 1;
	hasminusone = ai == -1;
}

int solve(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	bool hasone      = false;
	bool hasminusone = false;

	if (a[0] != b[0]) {
		say("NO");
		return 0;
	}
	update(hasone, hasminusone, a[0]);
	for (int i = 1; i < n; ++i) {
		if (b[i] > 0) {
			if (hasone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == 1 and a[i] == 1) {
				hasone = true;
				continue;
			}
			else {
				say("NO");
				return 0;;
			}
		}
		if (b[i] < 0) {
			if (hasminusone) {
				update(hasone, hasminusone, a[i]);
				continue;
			}
			if (b[i] == -1 and a[i] == -1) {
				hasminusone = true;
				continue;
			}
			else {
				say("NO");
				return 0;
			}
		}
		if (b[i] == 0) {
			if (a[i] == 0) {
				continue;
			}
			if (a[i] == 1) {
				if (hasminusone) {
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
			if (a[i] == -1) {
				if (hasone) {
					continue;
				}
				else {
					say("NO");
					return 0;
				}
			}
		}
	}
	say("YES");
	return 0;

}

int main()
{
	unsigned int T;
	cin >> T;

	for (size_t t = 0; t < T; ++t) {
		int n; cin >> n;
		vector<int> a, b;
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			a.push_back(tmp);
		}
		for (int i = 0; i < n; ++i) {
			int tmp; cin >> tmp;
			b.push_back(tmp);
		}
		solve(a, b);
	}
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

bool comp(int a , int b , bool one , bool neg){
    if(one && neg==false){
        return a <= b;
    }
    else if(neg && one==false){
        return a >= b;
    }
    else return true;
}

void solve(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
        cin>>b[i];

    int start=0;
    while(a[start]==0 && start<n){
        start++;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    for(int i=0;i<=start;i++){
        if(a[i]!=b[i]){
            cout<<"NO\n";
            return ;
        }
    }

    bool one=(a[start]==1);
    bool neg=(a[start]==-1);

    for(int i=start+1;i<n;i++){
        if(comp(a[i],b[i],one,neg) == false){
            cout<<"NO\n";
            return ;
        }
        if(one==false)
                one=(a[i]==1);
            if(neg==false)
                neg=(a[i]==-1);}

        cout<<"YES"<<endl;

}

int main(){
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

bool comp(int a , int b , bool one , bool neg){
    if(one && neg==false){
        return a <= b;
    }
    else if(neg && one==false){
        return a >= b;
    }
    else return true;
}

void solve(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
        cin>>b[i];

    int start=0;
    while(a[start]==0 && start<n){
        start++;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    for(int i=0;i<=start;i++){
        if(a[i]!=b[i]){
            cout<<"NO\n";
            return ;
        }
    }

    bool one=(a[start]==1);
    bool neg=(a[start]==-1);

    for(int i=start+1;i<n;i++){
        if(one==false)
            one=(a[i]==1);
        if(neg==false)
            neg=(a[i]==-1);

        if(comp(a[i],b[i],one,neg) == false){
            cout<<"NO\n";
            return ;
        }
    }

    cout<<"YES"<<endl;

}

int main(){
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

void solve(){
    int n ;
    cin>>n;
    int a[n], b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    bool ok=true;

    int start=0;
    while(a[start]==0){
        if(b[start]!=0)ok=false;
        start++;
    }
    if(ok==false || a[start]!=b[start]){
        cout<<"NO\n";
        return ;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    bool ones=false , negones=false;
    ones|=(a[start]==1);
    negones|=(a[start]==-1);
    for(int i=start+2;i<n;i++){
        if(ones&&!negones){
            if(a[start] > b[start])ok=false;
        }
        else if(!ones&&negones){
            if(a[start]<b[start])ok=false;
        }
        else continue;
    }

    if(ok)cout<<"YES\n";
    else cout<<"NO\n";

    return ;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

void solve(){
    int n ;
    cin>>n;
    int a[n], b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    bool ok=true;

    int start=0;
    while(start<n && a[start]==0){
        if(b[start]!=0)ok=false;
        start++;
    }
    if(ok==false || a[start]!=b[start]){
        cout<<"NO\n";
        return ;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    bool ones=false , negones=false;
    ones|=(a[start]==1);
    negones|=(a[start]==-1);
    for(int i=start+2;i<n;i++){
        if(ones&&!negones){
            if(a[start] > b[start])ok=false;
        }
        else if(!ones&&negones){
            if(a[start]<b[start])ok=false;
        }
        else continue;
    }

    if(ok)cout<<"YES\n";
    else cout<<"NO\n";

    return ;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

bool comp(int a , int b , int flag){
    if(flag==1){
        return a <= b;
    }
    else if(flag==-1){
        return a >= b;
    }
    else return true;
}

void solve(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
        cin>>b[i];

    int start=0;
    while(a[start]==0 && start<n){
        start++;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    for(int i=0;i<=start;i++){
        if(a[i]!=b[i]){
            cout<<"NO\n";
            return ;
        }
    }

    int one=(a[start]==1);
    int neg=(a[start]==-1);

    for(int i=start+1;i<n;i++){
        one=(a[i]==1);
        neg=(a[i]==-1);

        if(comp(a[i],b[i],one+neg) == false){
            cout<<"NO\n";
            return ;
        }
    }

    cout<<"YES"<<endl;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

void solve(){
    int n ;
    cin>>n;
    int a[n], b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    bool ok=true;

    int start=0;
    while(start<n && a[start]==0){
        if(b[start]!=0)ok=false;
        start++;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    if(ok==false || a[start]!=b[start]){
        cout<<"NO\n";
        return ;
    }

    bool ones=false , negones=false;
    ones|=(a[start]==1);
    negones|=(a[start]==-1);
    for(int i=start+2;i<n;i++){
        if(ones&&!negones){
            if(a[start] > b[start])ok=false;
        }
        else if(!ones&&negones){
            if(a[start]<b[start])ok=false;
        }
        else continue;
    }

    if(ok)cout<<"YES\n";
    else cout<<"NO\n";

    return ;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

void solve(){
    int n ;
    cin>>n;
    int a[n], b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    bool ok=true;

    int start=0;
    while(start<n && a[start]==0){
        if(b[start]!=0)ok=false;
        start++;
    }

    if(start==n&&ok){
        cout<<"YES\n";
        return ;
    }

    if(ok==false || a[start]!=b[start]){
        cout<<"NO\n";
        return ;
    }

    bool ones=false , negones=false;
    for(int i=start;i<n;i++){
        if(ones&&!negones){
            if(a[i] > b[i])ok=false;
        }
        else if(!ones&&negones){
            if(a[i]<b[i])ok=false;
        }
        ones|=(a[i]==1);
        negones|=(a[i]==-1);
    }

    if(ok)cout<<"YES\n";
    else cout<<"NO\n";

    return ;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cout<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

void solve(){
    int n ;
    cin>>n;
    int a[n], b[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];

    bool ok=true;

    int start=0;
    while(a[start]==0&&start<n){
        if(b[start]!=0)ok=false;
        start++;
    }
    if(ok==false || a[start]!=b[start]){
        cout<<"NO\n";
        return ;
    }

    if(start==n){
        cout<<"YES\n";
        return ;
    }

    bool ones=false , negones=false;
    ones|=(a[start]==1);
    negones|=(a[start]==-1);
    for(int i=start+2;i<n;i++){
        if(ones&&!negones){
            if(a[start] > b[start])ok=false;
        }
        else if(!ones&&negones){
            if(a[start]<b[start])ok=false;
        }
        else continue;
    }

    if(ok)cout<<"YES\n";
    else cout<<"NO\n";

    return ;

}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
			if (second[i] != first[i])
				v.push_back(i);
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool cc = true;

		for (int num = v.size() - 1; num >= 0; num--)
		{
			bool check = false;

			for (int i = 0; i < v[num]; i++)
			{
				if (first[i] == 0)	 continue;

				if (first[i] > 0 && second[v[num]] <= 0)
					continue;

				if (first[i] < 0 && second[v[num]] >= 0)
					continue;

				if (first[i] > 0)
				{
					if (second[v[num]] <= first[i])
						continue;
				}
				else
				{
					if (second[v[num]] >= first[i])
						continue;
				}

				int f = abs(first[i]);
				int s = abs(second[v[num]]);

				if (s % f == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool pos = 0, neg = 0;

		if (first[0] == 1)
			pos = 1;
		if (first[0] == -1)
			neg = 1;

		bool ans = true;

		for (int i = 1; i <= n; i++)
		{
			if (first[i] == second[i]) continue;

			if (first[i] > second[i])
			{
				if (!neg)
					ans = false;
			}
			else
			{
				if (!pos)
					ans = false;
			}

			if (first[i] == 1)
				pos = 1;
			if (first[i] == -1)
				neg = 1;
		}

		if (ans)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100000] = { 0, };
		int second[100000] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
			if (second[i] != first[i])
				v.push_back(i);
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}
		bool cc = true;

		for (int num = v.size() - 1; num >= 0; num--)
		{
			bool check = false;

			for (int i = 0; i < v[num]; i++)
			{
				if (first[i] > 0 && second[v[num]] < 0)
					continue;

				if (first[i] < 0 && second[v[num]]> 0)
					continue;

				int f = abs(first[i]);
				int s = abs(second[v[num]]);

				if (f == 0)	 continue;

				if (s % f == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
			if (second[i] != first[i])
				v.push_back(i);
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool cc = true;

		for (int num = v.size() - 1; num >= 0; num--)
		{
			bool check = false;

			for (int i = 0; i < v[num]; i++)
			{
				if (first[i] == 0)	 continue;

				if (first[i] > 0 && second[v[num]] <= 0)
					continue;

				if (first[i] < 0 && second[v[num]] >= 0)
					continue;

				if (first[i] > 0)
				{
					if (second[v[num]] < first[i])
						continue;
				}
				else
				{
					if (second[v[num]] > first[i])
						continue;
				}

				int f = abs(first[i]);
				int s = abs(second[v[num]]);

				if (s % f == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
			if (second[i] != first[i])
				v.push_back(i);
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool cc = true;

		for (int num = v.size() - 1; num >= 0; num--)
		{
			bool check = false;

			for (int i = 0; i < v[num]; i++)
			{
				if (first[i] == 0)	 continue;

				int s = second[v[num]] - first[v[num]];

				if (first[i] > 0 && s <= 0)
					continue;

				if (first[i] < 0 && s >= 0)
					continue;

				if (abs(s) % abs(first[i]) == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool cc = true;

		for (int num = 0; num < n; num++)
		{
			if (first[num] == second[num]) continue;

			bool check = false;

			for (int i = 0; i < num; i++)
			{

				int s = second[num] - first[num];

				if (first[i] == 0)
				{
					if (s == 0)
					{
						check = true;
						break;
					}
					else
						continue;
				}

				if (first[i] > 0 && s <= 0)
					continue;

				if (first[i] < 0 && s >= 0)
					continue;

				if (abs(s) % abs(first[i]) == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool pos = 0, neg = 0;

		if (first[0] == 1)
			pos = 1;
		if (first[0] == -1)
			neg = 1;

		bool ans = true;

		for (int i = 1; i < n; i++)
		{
			if (first[i] == second[i]) continue;

			if (first[i] > second[i])
			{
				if (!neg)
					ans = false;
			}
			else
			{
				if (!pos)
					ans = false;
			}

			if (first[i] == 1)
				pos = 1;
			if (first[i] == -1)
				neg = 1;
		}

		if (ans)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool pos = false, neg = false;

		if (first[0] == 1)
			pos = true;
		if (first[0] == -1)
			neg = true;

		bool ans = true;

		for (int i = 1; i < n; i++)
		{
			if (first[i] == second[i]);
			else if (first[i] > second[i])
			{
				if (neg == false)
					ans = false;
			}
			else
			{
				if (pos == false)
					ans = false;
			}

			if (first[i] == 1)
				pos = true;
			if (first[i] == -1)
				neg = true;
		}

		if (ans)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int T;
	cin >> T;

	while (T--)
	{
		int n;
		cin >> n;

		int first[100001] = { 0, };
		int second[100001] = { 0, };

		for (int i = 0; i < n; i++)
			cin >> first[i];

		vector<int> v;

		for (int i = 0; i < n; i++)
		{
			cin >> second[i];
			if (first[i] != second[i])
				v.push_back(i);
		}

		if (first[0] != second[0])
		{
			cout << "NO\n";
			continue;
		}

		bool cc = true;

		for (int num = 0; num < v.size(); num++)
		{
			bool check = false;

			for (int i = 0; i < v[num]; i++)
			{
				if (first[i] == 0)	 continue;

				int s = second[v[num]] - first[v[num]];

				if (first[i] > 0 && s <= 0)
					continue;

				if (first[i] < 0 && s >= 0)
					continue;

				if (abs(s) % abs(first[i]) == 0)
				{
					check = true;
					break;
				}
			}

			if (!check)
			{
				cc = false;
				break;
			}
		}

		if (cc)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int coun_1=0,coun1=0,coun0=0;
        int n;
        cin>>n;
        ll a[n+1];
        ll b[n+1];
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++)cin>>b[i];
        int f=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]==b[i]){
                if(a[i]<0)coun_1++;
                else if(a[i]==1)
                coun1++;
                else coun0++;
            }
            else
            {
                if(b[i]>0 )
                {
                    if(coun1>0){
                        if(a[i]<0)coun_1++;
                        else if(a[i]==1)coun1++;
                        else coun0++;
                        continue;
                    }
                    else{
                        f=0;break;
                    }
                }

                else if(b[i]==0)
                {
                    if(a[i]==-1)
                    {
                        if(coun1>0)
                        {
                            coun_1++;continue;
                        }
                        else {
                            f=0;break;
                        }
                    }
                    else if(a[i]==1)
                    {
                        if(coun_1>0)
                        {
                            coun1++;continue;
                        }
                        else{
                            f=0;break;
                        }
                    }

                }
                else if(b[i]<0)
                {
                        if(coun_1>0)
                        {
                            coun0++;
                            continue;
                        }
                        else{
                            f=0;break;
                        }
                }
            }

        }
        if(f==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        map<int,int>mp;
        mp[-1]=0,mp[1]=0;
        cin>>n;
        //cin>>n;
        int a[n+2],b[n+2];
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++)cin>>b[i];
        int f=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]==b[i]){
                mp[a[i]]++;
                continue;
            }
            else
            {
                if(a[i]<b[i])
                {
                    if(mp[1]==0)
                    {
                        f=1;break;
                    }
                    else mp[a[i]]++;
                }
                else if(a[i]>b[i])
                {
                    if(mp[-1]==0)
                    {
                        f=1;break;
                    }
                    else mp[a[i]]++;
                }
            }

        }
        if(f==0)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n;
        int coun0=0,coun1=0,coun=0;
        vector<ll>a,b;
        for(int i=0;i<n;i++){
            cin>>x;
            a.push_back(x);
        }
        for(int i=0;i<n;i++){
            cin>>x;
            b.push_back(x);
        }
        int f=1;
        for(int i=0;i<n;i++)
        {
           if(a[i]==b[i])
           {
               if(a[i]==1)coun1++;
               else if(a[i]==0)coun0++;
               else coun++;
           }
           else
           {
               if(b[i]>=0)
               {
                   if(coun1>0)
                   {
                       if(a[i]==1)coun1++;
                       else if(a[i]==0)coun0++;
                       else coun++;
                   }
                   else{
                    f=0;break;
                   }
               }

               else if(b[i]<0)
               {
                   if(a[i]==-1 || coun>0)
                   {
                       if(a[i]==1)coun1++;
                       else if(a[i]==0)coun0++;
                       else coun++;
                   }
                   else{
                      f=0;break;
                   }
               }
               else if(b[i]==0)
               {
                   if(a[i]==-1 && coun1>0)
                   {
                       coun++;
                       continue;
                   }
                   else if(a[i]==1 && coun>0)
                   {
                       coun1++;
                       continue;
                   }
                   else{
                    f=0;break;
                   }
               }
           }
        }
        if(f==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n;
        int coun0=0,coun1=0,coun=0;
        vector<ll>a,b;
        for(int i=0;i<n;i++){
            cin>>x;
            a.push_back(x);
        }
        for(int i=0;i<n;i++){
            cin>>x;
            b.push_back(x);
        }
        int f=1;
        for(int i=0;i<n;i++)
        {
           if(a[i]==b[i])
           {
               if(a[i]==1)coun1++;
               else if(a[i]==0)coun0++;
               else coun++;
           }
           else
           {
               if(b[i]>=0)
               {
                   if(coun1>0)
                   {
                       if(a[i]==1)coun1++;
                       else if(a[i]==0)coun0++;
                       else coun++;
                   }
                   else{
                    f=0;break;
                   }
               }

               else if(b[i]<0)
               {
                   if(a[i]==-1 && i!=0)
                   {
                       coun++;continue;
                   }
                   else if(coun>0)
                      continue;
                   else{
                      f=0;break;
                   }
               }
               else if(b[i]==0)
               {
                   if(a[i]==-1 && coun1>0)
                   {
                       coun++;
                       continue;
                   }
                   else if(a[i]==1 && coun>0)
                   {
                       coun1++;
                       continue;
                   }
                   else{
                    f=0;break;
                   }
               }
           }
        }
        if(f==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n;
        int coun0=0,coun1=0,coun=0;
        vector<ll>a,b;
        for(int i=0;i<n;i++){
            cin>>x;
            a.push_back(x);
        }
        for(int i=0;i<n;i++){
            cin>>x;
            b.push_back(x);
        }
        int f=1;
        for(int i=0;i<n;i++)
        {
           if(a[i]==b[i])
           {
               if(a[i]==1)coun1++;
               else if(a[i]==0)coun0++;
               else coun++;
           }
           else
           {
               if(b[i]>=0)
               {
                   if(coun1>0)
                   {
                       if(a[i]==1)coun1++;
                       else if(a[i]==0)coun0++;
                       else coun++;
                   }
                   else{
                    f=0;break;
                   }
               }

               else if(b[i]<0)
               {
                   if(a[i]==-1 && coun>0)
                   {
                       if(a[i]==1)coun1++;
                       else if(a[i]==0)coun0++;
                       else coun++;
                   }
                   else{
                      f=0;break;
                   }
               }
               else if(b[i]==0)
               {
                   if(a[i]==-1 && coun1>0)
                   {
                       coun++;
                       continue;
                   }
                   else if(a[i]==1 && coun>0)
                   {
                       coun1++;
                       continue;
                   }
                   else{
                    f=0;break;
                   }
               }
           }
        }
        if(f==1)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int coun_1=0,coun1=0,coun0;
        int n;
        cin>>n;
        int a[n+1];
        int b[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
        }
        int f=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]==b[i]){
                if(a[i]<0)coun_1++;
                else if(a[i]==1)
                coun1++;
                else coun0++;

            }
            else
            {
                if(b[i]>0 )
                {
                    if(coun1>0){
                        if(a[i]<0)coun_1++;
                        else if(a[i]==1)coun1++;
                        else coun0++;
                    }
                    else{
                        f=0;break;
                    }
                }

                else if(b[i]==0)
                {
                    if(a[i]==-1)
                    {
                        if(coun1>0)
                        {
                            coun_1++;continue;
                        }
                        else {
                            f=0;break;
                        }
                    }
                    else if(a[i]==1)
                    {
                        if(coun_1>0)
                        {
                            coun1++;continue;
                        }
                        else{
                            f=0;break;
                        }
                    }

                }
                else if(b[i]<0)
                {
                        if(coun_1>0)
                        {
                            coun0++;
                            continue;
                        }
                        else{
                            f=0;break;
                        }

                }
            }

        }
        if(f==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int coun_1=0,coun1=0,coun0=0;
        int n;
        cin>>n;
        int a[n+1];
        int b[n+1];
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++)cin>>b[i];
        int f=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]==b[i]){
                if(a[i]<0)coun_1++;
                else if(a[i]==1)
                coun1++;
                else coun0++;
            }
            else
            {
                if(b[i]>0 )
                {
                    if(coun1>0){
                        if(a[i]<0)coun_1++;
                        else if(a[i]==1)coun1++;
                        else coun0++;
                        continue;
                    }
                    else{
                        f=0;break;
                    }
                }

                else if(b[i]==0)
                {
                    if(a[i]==-1)
                    {
                        if(coun1>0)
                        {
                            coun_1++;continue;
                        }
                        else {
                            f=0;break;
                        }
                    }
                    else if(a[i]==1)
                    {
                        if(coun_1>0)
                        {
                            coun1++;continue;
                        }
                        else{
                            f=0;break;
                        }
                    }

                }
                else if(b[i]<0)
                {
                        if(coun_1>0)
                        {
                            coun0++;
                            continue;
                        }
                        else{
                            f=0;break;
                        }
                }
            }

        }
        if(f==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	vii fib;
	// ll a=0, b=1, mx=1e9;
	// while(b<=mx){
	// 	fib.pb(b);
	// 	int x=a;
	// 	a=b;
	// 	b=x+a;
	// }
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO\n";
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			if(a[i]==b[i])continue;
			--m[a[i]];
			if(b[i]>0){
				if(m[1]<1){
					res="NO";
					break;
				}
			}
			else if(b[i]<0){
				if(m[-1]<1){
					res="NO";
					break;
				}
			}
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		string res="YES";
		for(int i=n;i--;){
			--m[a[i]];
			if(a[i]==b[i] || (b[i]>0 && m[1]>0) || (b[i]<0 && m[-1]>0))continue;
			else{
				res="NO";
				break;
			}
		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO"<<endl;
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			--m[a[i]];
			if(b[i]>0 && m[1]>0)continue;
			else if(b[i]<0 && m[-1]>0) continue;
			else if(b[i]==0 && ((a[i]==-1 && m[1]>0) || (a[i]==1 && m[-1]>0)))continue;
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO\n";
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			--m[a[i]];
			if(b[i]>0 && m[1]>0)continue;
			else if(b[i]<0 && m[-1]>0) continue;
			else if(b[i]==0 && ((a[i]==-1 && m[1]>0) || (a[i]==1 && m[-1]>0)))continue;
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int, custom_hash>
#define usl unordered_set<long long int, custom_hash>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int, custom_hash>
#define uml unordered_map<long long int, long long int, custom_hash>
#define ski stack<int>
#define skl stack<long long int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N=2e5+1;
const int mod=998244353;
ll a[N], b[N], c[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		string res="YES";
		// for(int i=n-1;i>=0;i--){
		// 	--m[a[i]];
		// 	if(a[i]==b[i] || (b[i]>a[i] && m[1]>0) || (b[i]<a[i] && m[-1]>0))continue;
		// 	if(b[i]==0 && ((a[i]>0 && m[-1]>0) || (a[i]<0 && m[1]>0))) continue;
		// 	else{
		// 		res="NO";
		// 		break;
		// 	}
		// }

		for(int i=n;i--;){
			--m[a[i]];
			if(a[i]==b[i] || (b[i]>0 && m[1]>0) || (b[i]<0 && m[-1]>0))continue;
			if(b[i]==0 && ((a[i]>0 && m[-1]>0) || (a[i]<0 && m[1]>0))) continue;
			else{
				res="NO";
				break;
			}
		}

		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO\n";
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			if(a[i]==b[i])continue;

			--m[a[i]];
			if(b[i]>0 && m[1]>0)continue;
			else if(b[i]<0 && m[-1]>0) continue;
			else if(b[i]==0 && (m[1]>0 || m[-1]>0))continue;
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int, custom_hash>
#define usl unordered_set<long long int, custom_hash>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int, custom_hash>
#define uml unordered_map<long long int, long long int, custom_hash>
#define ski stack<int>
#define skl stack<long long int>
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N=2e5+1;
const int mod=998244353;
ll a[N], b[N], c[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		string res="YES";
		for(int i=n-1;i>=0;i--){
			--m[a[i]];
			if(a[i]==b[i] || (b[i]>a[i] && m[1]>0) || (b[i]<a[i] && m[-1]>0))continue;
			if(b[i]==0 && ((a[i]>0 && m[-1]>0) || (a[i]<0 && m[1]>0))) continue;
			else{
				res="NO";
				break;
			}
		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO"<<endl;
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			--m[a[i]];
			if(b[i]>0 && m[1]>0)continue;
			else if(b[i]<0 && m[-1]>0) continue;
			else if(b[i]==0 && ((a[i]==-1 && m[1]>0) || (a[i]==1 && m[-1]>0) || a[i]==0))continue;
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif

	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		string res="YES";
		for(int i=n;i--;){
			--m[a[i]];
			if(a[i]==b[i] || (b[i]>a[i] && m[1]>0) || (b[i]<a[i] && m[-1]>0))continue;
			else{
				res="NO";
				break;
			}
		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO\n";
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			if(a[i]==b[i])continue;

			--m[a[i]];

			if(b[i]>0 && m[1]>0)continue;
			else if(b[i]<0 && m[-1]>0) continue;
			else if(b[i]==0 && ((a[i]==-1 && m[1]>0) || (a[i]==1 && m[-1]>0)))continue;
			else{
				res="NO";
				break;
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int>
#define usl unordered_set<long long int>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int>
#define uml unordered_map<long long int, long long int>
#define ski stack<int>
#define skl stack<long long int>

using namespace std;

const int N=2e5+1;
const int mod=998244353;
int a[N], b[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	int t;
	cin>>t;
	vii fib;
	// ll a=0, b=1, mx=1e9;
	// while(b<=mx){
	// 	fib.pb(b);
	// 	int x=a;
	// 	a=b;
	// 	b=x+a;
	// }
	while(t--){
		int n;
		cin>>n;

		umi m;
		for(int i=0;i<n;++i){
			cin>>a[i];
			m[a[i]]++;
		}
		for(int i=0;i<n;++i){
			cin>>b[i];
		}
		if(a[0]!=b[0]){
			cout<<"NO\n";
			continue;
		}
		string res="YES";
		for(int i=n-1;i>0;--i){
			if(a[i]==b[i])continue;
			--m[a[i]];
			if(b[i]>0){
				if(m[1]<1){
					res="NO";
					break;
				}
			}
			else if(b[i]<0){
				if(m[-1]<1){
					res="NO";
					break;
				}
			}
			else{
				if((a[i]==1 && m[-1]<=0) || (a[i]==-1 && m[1]<=0)){
					res="NO";
					break;
				}
			}

		}
		cout<<res<<endl;
	}

}


#include <bits/stdc++.h>
// #include <numeric>
#define ll long long int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define pb push_back
using namespace std;
void solve(){
  int n;cin>>n;std::vector<int> v(n),A(n);int a=-1,b=-1;
  for (int i = 0; i < n; ++i)
  {
    cin>>v[i];if(a==-1 and v[i]==-1)a=i;
    if(b==-1 and v[i]==1)b=i;
  }
  bool c=0;
  for (int i = 0; i < n; ++i)
  {
    cin>>A[i];
    if(A[i]>v[i]){
      if(b>=i or b==-1)c=1;
    }
    if(A[i]<v[i]){
      if(a>=i or a==-1)c=1;
    }
  }
  if(c)cout<<"NO";
  else cout<<"YES";
}
int main()
{
    ibs;cti;
    int t;cin>>t;
    while(t--){
      solve();
      cout<<"\n";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
using namespace std;
int main()
{
    int t,n,m;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++){
            if(i==n-1&&j==m-1)
            cout<<"W";
            else cout<<"B";
            }
            cout<<endl;
        }

    }
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ull unsigned long long
using namespace std;
int main()
{
    ull int t,n,m,res,count1,countminus1,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        res=1;
        count1=0,countminus1=0;
        vector<ull int> a(n),b(n);
        for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
            continue;
        }
        else if(a[i]<b[i])
        {
            if(!count1)
            res=0;
            break;
        }
        else if(a[i]>b[i])
        {
            if(!countminus1)
            res=0;
            break;
        }
        if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
    }
    if(res==0)
    cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

    }
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ull unsigned long long
using namespace std;
int main()
{
    ull int t,n,m,res,count1,countminus1,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        res=1;
        count1=0,countminus1=0;
        vector<ull int> a(n),b(n);
        for(int i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
            continue;
        }
        else if(a[i]<b[i])
        {
            if(!count1)
            res=0;
            break;
        }
        else if(a[i]>b[i])
        {
            if(!countminus1)
            res=0;
            break;
        }
        if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
    }
    if(res==0)
    cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

    }
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
using namespace std;
int main()
{
    ll int t,n,m,res,count1,countminus1,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        res=1;
        count1=0,countminus1=0;
        vector<ll int> a(n),b(n);
        for(int i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
            continue;
        }
        else if(a[i]<b[i])
        {
            if(!count1)
            res=0;
            break;
        }
        else if(a[i]>b[i])
        {
            if(!countminus1)
            res=0;
            break;
        }
        if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
    }
    if(res==0)
    cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

    }
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
using namespace std;
int main()
{
    ll int t,n,m,res,count1,countminus1,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        res=1;
        count1=0,countminus1=0;
        vector<ll int> a(n),b(n);
        for(int i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
            continue;
        }
        else if(a[i]<b[i])
        {
            if(!count1)
            res=0;
            break;
        }
        else if(a[i]>b[i])
        {
            if(!countminus1)
            res=0;
            break;
        }
        if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
    }
    if(res==0)
    cout<<"NO"<<"\n";
    else cout<<"YES"<<"\n";

    }
}


#include <iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
using namespace std;
int main()
{
    ll int t,n,m,res,count1,countminus1,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        res=1;
        count1=0,countminus1=0;
        vector<ll int> a(n),b(n);
        for(int i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
            continue;
        }
        else if(a[i]<b[i])
        {
            if(!count1)
            res=0;

        }
        else if(a[i]>b[i])
        {
            if(!countminus1)
            res=0;

        }
        if(a[i]==-1)
            countminus1++;
            else if(a[i]==1)
            count1++;
    }
    if(res==0)
    cout<<"NO"<<"\n";
    else cout<<"YES"<<"\n";

    }
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }
        else
        {
            for (int i = n - 1; i > 0; i--)
            {
                int flag = 0;
                if (a[i] > b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] == -1)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
                else if (a[i] == b[i])
                {
                    continue;
                }
                else if (a[i] < b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] > 0)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }

        for (int i = n - 1; i > 0; i--)
        {
            int flag = 0;
            if (a[i] > b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] < 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
            else if (a[i] < b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] > 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
            ;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }

        for (int i = n - 1; i > 0; i--)
        {
            int flag = 0;
            if (a[i] > b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] < 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                    break;
                }
            }
            else if (a[i] < b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] > 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                    break;
                }
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }
        else
        {
            for (int i = n - 1; i > 0; i--)
            {
                int flag = 0;
                if (a[i] > b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] == -1)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
                else if (a[i] < b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] > 0)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
                else if (a[i] = b[i])
                {
                    continue;
                }
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }

        for (int i = n - 1; i > 0; i--)
        {
            int flag = 0;
            if (a[i] > b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] < 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
            else if (a[i] < b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] > 0)
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
            if (e == -1)
            {
                break;
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }
        else
        {
            for (int i = n - 1; i > 0; i--)
            {
                int flag = 0;
                if (a[i] > b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] == -1)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
                else if (a[i] = b[i])
                {
                    continue;
                }
                else if (a[i] < b[i])
                {
                    for (int w = 0; w < i; w++)
                    {
                        if (a[w] > 0)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 0)
                    {
                        e = -1;
                        cout << "NO" << endl;
                        break;
                    }
                }
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <queue>

using namespace std;

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

    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        cin >> n;
        int a[n];
        int b[n];

        int e = 0;
        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            a[i] = x;
        }

        for (int i = 0; i < n; i++)
        {
            int x;
            cin >> x;
            b[i] = x;
        }

        if (a[0] != b[0])
        {
            e = -1;
            cout << "NO" << endl;
        }

        for (int i = n - 1; i > 0; i--)
        {
            int flag = 0;
            if (a[i] > b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] < 0)
                    {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
            else if (a[i] < b[i])
            {
                for (int w = 0; w < i; w++)
                {
                    if (a[w] > 0)
                    {
                        flag = 1;
                        break;
                    }
                }
                if (flag == 0)
                {
                    e = -1;
                    cout << "NO" << endl;
                }
            }
            else if (a[i] = b[i])
            {
                continue;
            }
            if (e == -1)
            {
                break;
            }
        }
        if (e != -1)
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a[100002];
int b[100002];
int main()
{

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

    int n;cin>>n;

    bool c=0,d=0,ans=1;
    for(int i=0;i<n;i++){cin>>a[i];}
    for(int i=0;i<n;i++)cin>>b[i];
bool pos_one = 0,neg_one = 0;

if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}
    for(int i=0;i<n;i++){
if(a[i]<b[i]&&pos_one==0){ans=0;break;}

if(a[i]>b[i]&&neg_one==0){ans=0;break;}
 if(a[i]==1)pos_one=1;
 if(a[i]==-1)neg_one=1;

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a[100002];
int b[100002];
int main()
{

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

    int n;cin>>n;

    bool c=0,d=0,ans=1;
    for(int i=0;i<n;i++){cin>>a[i];}
    for(int i=0;i<n;i++)cin>>b[i];
    if(a[0]==0&&b[0]!=0){cout<<"NO"<<endl;continue;}
    if(a[0]==0&&(a[1]!=b[1])){cout<<"NO"<<endl;continue;}
    if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}
vector<int>v;
if(a[0]<0)v.push_back(-1);
if(a[0]>0)v.push_back(1);

    for(int i=1;i<n;i++){
if(a[i]<b[i]&&v[i-1]!=1)ans=0;

if(a[i]>b[i]&&v[i-1]!=-1)ans=0;
 v.push_back(a[i]);

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a,b,c,d;

int main()
{

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

    int n;cin>>n;
    int a[n],b[n];
    bool c=0,d=0,ans=0;
    for(int i=0;i<n;i++){cin>>a[i];if(a[i]==1)c=1;if(a[i]==(-1))d=1;}
    for(int i=0;i<n;i++)cin>>b[i];
    if(a[0]==0&&b[0]!=0){cout<<"NO"<<endl;continue;}
    if(a[0]==0&&(a[1]!=b[1])){cout<<"NO"<<endl;continue;}
    //if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}

    for(int i=1;i<n;i++){

        if(a[i]!=b[i]&&b[i]>=0){
            if(c)ans=1;
            else ans=0;
        }
        if(a[i]!=b[i]&&b[i]<=0){
            if(d)ans=1;else ans=0;
        }

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a[100002];
int b[100002];
int main()
{

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

    int n;cin>>n;

    bool c=0,d=0,ans=1;
    for(int i=0;i<n;i++){cin>>a[i];}
    for(int i=0;i<n;i++)cin>>b[i];

vector<int>v;
v.push_back(a[0]);

if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}
    for(int i=1;i<n;i++){
if(a[i]<b[i]&&v[i-1]!=1)ans=0;

if(a[i]>b[i]&&v[i-1]!=-1)ans=0;
 v.push_back(a[i]);

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a,b,c,d;

int main()
{

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

    int n;cin>>n;
    int a[n],b[n];
    bool c=0,d=0,ans=0;
    for(int i=0;i<n;i++){cin>>a[i];if(a[i]==1)c=1;if(a[i]==(-1))d=1;}
    for(int i=0;i<n;i++)cin>>b[i];
    if(a[0]==0&&b[0]!=0){cout<<"NO"<<endl;continue;}
    if(a[0]==0&&(a[1]!=b[1])){cout<<"NO"<<endl;continue;}
    if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}

    for(int i=1;i<n;i++){

        if(a[i]!=b[i]&&b[i]>=0){
            if(c)ans=1;
            else ans=0;
        }
        if(a[i]!=b[i]&&b[i]<=0){
            if(d)ans=1;else ans=0;
        }

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int a,b,c,d;

int main()
{

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

    int n;cin>>n;
    int a[n],b[n];
    bool c=0,d=0,ans=1;
    for(int i=0;i<n;i++){cin>>a[i];if(a[i]==1)c=1;if(a[i]==(-1))d=1;}
    for(int i=0;i<n;i++)cin>>b[i];
    if(a[0]==0&&b[0]!=0){cout<<"NO"<<endl;continue;}
    if(a[0]==0&&(a[1]!=b[1])){cout<<"NO"<<endl;continue;}
    if(a[0]!=b[0]){cout<<"NO"<<endl;continue;}

    for(int i=1;i<n;i++){

        if(a[i]!=b[i]&&b[i]>=0){
            if(c)ans=1;
            else ans=0;
        }
        if(a[i]!=b[i]&&b[i]<=0){
            if(d)ans=1;else ans=0;
        }

    }
    if(ans)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}

}


#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long INT;
typedef pair<int,int> pii;

const int NN=100010;
const int inf=0x3f3f3f3f;

int a[NN],b[NN];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	int t,n; cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++)scanf("%d",a+i);
		for(int i=0;i<n;i++)scanf("%d",b+i);
		if(a[0]!=b[0]){
			puts("NO");
			continue;
		}
		int ne=n,po=n;
		for(int i=0;i<n;i++){
			if(a[i]==-1)ne=min(ne,i);
			if(a[i]==1)po=min(po,i);
		}
		int f=1;
		for(int i=0;i<n;i++){
			if(b[i]>a[0] && i<=po){
				puts("NO");
				f=0;
				break;
			}
			if(b[i]<a[0] && i<=ne){
				puts("NO");
				f=0;
				break;
			}
		}
		if(f)puts("YES");
	}

	return 0;
}


#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long INT;
typedef pair<int,int> pii;

const int NN=100010;
const int inf=0x3f3f3f3f;

int a[NN],b[NN];

main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
#endif
	int t,n; cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++)scanf("%d",a+i);
		for(int i=0;i<n;i++)scanf("%d",b+i);
		if(a[0]!=b[0]){
			puts("NO");
			continue;
		}
		int ne=n,po=n;
		for(int i=0;i<n;i++){
			if(a[i]==-1)ne=min(ne,i);
			if(a[i]==1)po=min(po,i);
		}
		int f=1;
		for(int i=1;i<n;i++){
			if(b[i]>a[0] && i<=po){
				if(a[i]==1 && b[i]==b[i-1]+1)continue;
				puts("NO");
				f=0;
				break;
			}
			if(b[i]<a[0] && i<=ne){
				if(a[i]==-1 && b[i]==b[i-1]-1)continue;
				puts("NO");
				f=0;
				break;
			}
		}
		if(f)puts("YES");
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int a[100010],b[100010];
int f[5];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	int n;
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",a+i);
		for(int i=1;i<=n;i++)scanf("%d",b+i);
		for(int i=1;i<=3;i++)f[i]=0;
		if(a[1]==-1)f[1]=1;
		if(a[1]==0)f[2]=1;
		if(a[1]==1)f[3]=1;
		if(a[1]!=b[1]) {cout<<"NO"<<endl;continue;}
		int ff=0;
		for(int i=2;i<=n;i++){
			 if(b[i]==a[i]){
			 	if(!f[2] or (!f[1] and !f[3])) {ff=1;break;}
			 }
			 else if(b[i]<a[i]){
			 	if(!f[1]){ff=1;break;}
			 }
			 else {
			 	if(!f[3]){ff=1;break;}
			 }
//			 cout<<f[1]<<' '<<f[2]<<' '<<f[3]<<' '<<ff<<endl;
			 f[a[i]+2]=1;
			 if(ff==1)break;

		}
		if(ff)cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
int a[100010],b[100010];
int f[5];
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int t;
	cin>>t;
	int n;
	while(t--){
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",a+i);
		for(int i=1;i<=n;i++)scanf("%d",b+i);
		for(int i=1;i<=3;i++)f[i]=0;
		if(a[1]==-1)f[1]=1;
		if(a[1]==0)f[2]=1;
		if(a[1]==1)f[3]=1;
		if(a[1]!=b[1]) {cout<<"NO"<<endl;continue;}
		int ff=0;
		for(int i=2;i<=n;i++){
			 if(b[i]==a[i]){
			 	if(!f[2]){ff=1;break;}
			 	else if(!f[1] or !f[3]){ff=1;break;}
			 }
			 else if(b[i]<a[i]){
			 	if(!f[1]){ff=1;break;}
			 }
			 else {
			 	if(!f[3]){ff=1;break;}
			 }
//			 cout<<f[1]<<' '<<f[2]<<' '<<f[3]<<' '<<ff<<endl;
			 f[a[i]+2]=1;
			 if(ff==1)break;

		}
		if(ff)cout<<"NO"<<endl;
		else cout<<"YES"<<endl;
	}

	return 0;
}