#include<bits/stdc++.h>
using namespace std;

int a[102];
int main()
{
    int n;
    cin>>n;
    map<int,int>m1, m2;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        m1[ a[i] ]++;
    }
    int ans=0;
    for(auto z : m1)
    {
      ans += z.second/4;
      m2[z.first] = z.second%4;
    }
    int cnt=0;
    for(auto z : m2)
    {
      //cout<<z.first<<' '<<z.second<<endl;
      if(z.second >= 2){
        cnt++;
      }
    }
    ans+= (cnt/2);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int a[102];
int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        mp[ a[i] ]++;
    }
    int ans=0;
    for(auto z : mp)
    {
      ans += z.second/4;
      z.second %= 4;
    }
    int cnt=0;
    for(auto z : mp)
    {
      if(z.second >= 2){
        cnt++;
      }
    }
    ans+= (cnt/2);
    cout<<ans<<endl;
    return 0;
}


/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool
 * Author: OI_Master
 * Time: 2020-03-31 12:02:24
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    	cin>>a[i];
    int cnt[101]={0};
    for(int i=0;i<n;++i)
    	++cnt[a[i]];
    int sum=0;
    for(int i=0;i<n;++i)
    	sum+=cnt[i]/2;
    cout<<sum/2<<endl;
    return 0;
}


/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool
 * Author: OI_Master
 * Time: 2020-03-31 12:02:24
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    	cin>>a[i];
    int cnt[101]={0};
    for(int i=0;i<n;++i)
    	++cnt[a[i]];
    int sum=0;
    for(int i=0;i<=n;++i)
    	sum+=cnt[i]/2;
    cout<<sum/2<<endl;
    return 0;
}


/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool
 * Author: OI_Master
 * Time: 2020-03-31 12:02:24
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    	cin>>a[i];
    int cnt[101]={0};
    for(int i=0;i<n;++i)
    	++cnt[a[i]];
    int sum=0;
    for(int i=0;i<=100;++i)
    	sum+=cnt[i]/2;
    cout<<sum/2<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,x,i,a[1000];
main()
{
      cin>>n;
      for(i=0; i<n; i++)
      cin>>a[i];
      sort(a,a+n);
      for(i=0; i<n; i++)
      if(a[i]==a[i+1])
      {
                      x++;
                      i++;
      }
      cout<<x/2;
      //system("pause");
}


#include<iostream>
using namespace std;
int n,x,i,a[1000];
main()
{
      cin>>n;
      for(i=0; i<n; i++)
      cin>>a[i];
      sort(a,a+n);
      for(i=0; i<n; i++)
      if(a[i]==a[i+1])
      {
                      x++;
                      i++;
      }
      cout<<x/2;
      //system("pause");
}


///*Bismillahir Rahmanir Rahim***///
///**Author Thasin Sheikh**///
/*    #include <regex>
    ...
    std::string string("hello $name");
    string = std::regex_replace(string, std::regex("\\$name"), "Somename");
    */
/*while(a)
    {
        if(a%2==0)
            dvi.push_back(0);
        else
            dvi.push_back(1);
        a/=2;
    }
    reverse(dvi.begin(),dvi.end());
    for(i=0;i<dvi.size();i++)
        cout<<dvi[i];*/
#include<bits/stdc++.h>
using namespace std;
vector<int>primes;
#define MAX 35000
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
ll aarray[100000+10];
char magic[1][100000];
ll ar[200000+10];
const int N = 2e5 + 10;
int a[N];
int main()
{
    makefast__
    string ptr,str;
    ll m1,m2,m3,m4,i,j,x,y,n,k,m5,m,ta,t,flag=0,sum=0,ans=0;
    ll w1,w2,w3,w4,w5;
    vector<ll>dvi,cvi;
    ll count[100001];
    memset(count,0,sizeof(count));
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>k;
        count[k]++;
    }
    for(i=100; i>=1; i--)
    {
        if(count[i]>1)
        {
            dvi.push_back(count[i]);
        }
        else continue;
    }
    sort(dvi.begin(),dvi.end());
    reverse(dvi.begin(),dvi.end());
    for(i=0; i<dvi.size(); i++)
    {
        if(dvi[i]%2==1)
        {
            dvi[i]=dvi[i]-1;
        }
    }
    for(i=0;i<dvi.size();i++)
    {
        sum+=dvi[i];
    }
    cout<<sum/4<<endl;

}


///*Bismillahir Rahmanir Rahim***///
///**Author Thasin Sheikh**///
/*    #include <regex>
    ...
    std::string string("hello $name");
    string = std::regex_replace(string, std::regex("\\$name"), "Somename");
    */
/*while(a)
    {
        if(a%2==0)
            dvi.push_back(0);
        else
            dvi.push_back(1);
        a/=2;
    }
    reverse(dvi.begin(),dvi.end());
    for(i=0;i<dvi.size();i++)
        cout<<dvi[i];*/
#include<bits/stdc++.h>
using namespace std;
vector<int>primes;
#define MAX 35000
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
ll aarray[100000+10];
char magic[1][100000];
ll ar[200000+10];
const int N = 2e5 + 10;
int a[N];
int main()
{
    makefast__
    string ptr,str;
    ll m1,m2,m3,m4,i,j,x,y,n,k,m5,m,ta,t,flag=0,sum=0,ans=0;
    ll w1,w2,w3,w4,w5;
    vector<ll>dvi,cvi;
    ll count[101];
    memset(count,0,sizeof(count));
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>k;
        count[k]++;
    }
    for(i=101; i>=1; i--)
    {
        if(count[i]>1)
        {
            dvi.push_back(count[i]);
        }
    }
    sort(dvi.begin(),dvi.end());
    reverse(dvi.begin(),dvi.end());
    for(i=0; i<dvi.size(); i++)
    {
        if(dvi[i]%2==1)
        {
            dvi[i]=dvi[i]-1;
        }
    }
    for(i=0;i<dvi.size();i++)
    {
        sum+=dvi[i];
    }
    cout<<sum/4<<endl;

}


#include<iostream>
using namespace std;

int main()
{   int a,b,c[1000],count=0
    cin>>a;
    for(int i=0;i<a;i++){
            cin>>b;
            c[b]++;
            if (c[b]%2==0) count++;
            }
    cout<<count/2;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{   int a,b,c[1000],count=0;
    cin>>a;
    for(int i=0;i<a;i++){
            cin>>b;
            c[b]++;
            if (c[b]%2==0) count++;
            }
    cout<<count/2;
    return 0;
}


#define ll unsigned long long int
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define maxx(a,b) std::max(a,b)
#define maxxx(a,b,c) std::max(a,std::max(b,c))
#define minn(a,b) std::min(a,b)
#define minnn(a,b,c) std::min(a,std::min(b,c))

#define pii 3.14159265358979323846
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

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

        int n;
	    cin>>n;
	    int a[n],b[n];
	    forn(i,n)cin>>a[i];
	    forn(i,n)cin>>b[i];
	    bool ok=true,ok1=true;
	    int diff=0;
	    int mark=0;
	    forn(i,n)
	    {
	        if(a[i]!=b[i])
	        {
	            if(a[i]>b[i]){ok=false;break;}
	            else
	            {
	                diff=b[i]-a[i];

	                if(ok1&&diff>0)
	                {
	                    mark=b[i]-a[i];
	                    ok1=false;
	                }
	                if(!ok1)
	                {
	                    if(mark!=diff){ok=false;break;}
	                }
	            }
	        }
	    }
        if(ok)cout<<"YES"<<endl;
        if(!ok)cout<<"NO"<<endl;

      }
      return 0;
  }


#include<bits/stdc++.h>

typedef long long int ll;
typedef unsigned long long int ull;

#define dbg printf("in\n")
#define nl printf("\n")
#define N 101010
#define inf 1e9

#define sf(n) scanf("%d", &n)
#define sff(n,m) scanf("%d%d",&n,&m)
#define sfl(n) scanf("%I64d", &n)
#define sffl(n,m) scanf("%I64d%I64d",&n,&m)

#define pf(n) printf("%d",n)
#define pff(n,m) printf("%d %d",n,m)
#define pffl(n,m) printf("%I64d %I64d",n,m)
#define pfl(n) printf("%I64d",n)
#define pfs(s) printf("%s",s)

#define pb push_back
#define pp pair<int, int>

using namespace std;

int main()
{
    freopen("in.txt", "r", stdin);

    int i, j, k;
    int n, m, q;

    sf(q);
    while(q--)
    {
        sf(n);

        int a[n], b[n];
        for(i = 0; i < n; i++)
            sf(a[i]);
        for(i = 0; i < n; i++)
            sf(b[i]);

        bool f = true;
        k = 0; m = -1;
        for(i = 0; i < n; i++)
        {
            if(a[i] != b[i])
            {
                if(b[i] < a[i]){f = false; break;}
                k = b[i] - a[i];
                m = i;
                break;
            }
        }

        for(i = m; i < n; i++)
        {
            if(a[i] == b[i]) break;
            a[i] += k;
        }

        for(i = 0; i < n; i++)
        {
            if(a[i] != b[i]){
                f = false;
                break;
            }
        }

        if(f)
            pfs("YES\n");
        else
            pfs("NO\n");
    }

    return 0;
}


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

bool solve()
{
    int nbElem;
    cin >> nbElem;

    int extSize = nbElem+2;
    vector<int> orig(extSize), target(extSize);
    vector<int> diff(extSize, 0);

    for (int iElem = 1; iElem <= nbElem; ++iElem) {
        cin >> orig[iElem];
    }

    for (int iElem = 1; iElem <= nbElem; ++iElem) {
        cin >> target[iElem];
        diff[iElem] = target[iElem] - orig[iElem];
    }

    int cntModif = 0;
    for (int iElem = 0; iElem < extSize-1; ++iElem) {
        if (diff[iElem] < 0) {
            return false;
        }
        if (diff[iElem] != diff[iElem+1]) {
            ++cntModif;
        }
    }

    return (cntModif <= 2);
}

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

    int nbQueries;
    cin >> nbQueries;

    for (int iQuery = 0; iQuery < nbQueries; ++iQuery) {
        if (solve()) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }

    return 0;
}


#define ll unsigned long long int
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define maxx(a,b) std::max(a,b)
#define maxxx(a,b,c) std::max(a,std::max(b,c))
#define minn(a,b) std::min(a,b)
#define minnn(a,b,c) std::min(a,std::min(b,c))

#define pii 3.14159265358979323846
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

  int main()
  {
      int t;
      cin>>t;
      while(t--)
      {
        int n;
	    cin>>n;
	    int a[n],b[n];
	forn(i,n)cin>>a[i];
	forn(i,n)cin>>b[i];
	if(n==1)
	{
	    if(a[0]==b[0]){cout<<"YES"<<endl;continue;}
	    else {cout<<"NO"<<endl;continue;}
	}
	int ok=true;
	int ok1=true;
	int diff=0;
	forn(i,n)
	{
	    int temp=0;
	    temp=a[i]-b[i];
	    if(temp)
	    {
	        if(ok){diff=temp;ok=false;}
	        if(!ok)
	        {
	            if(temp!=diff){ok1=false;break;}
	        }
	    }

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

      }
      return 0;
  }


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

bool solve() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int &x : a) cin >> x;
  for (int &x : b) cin >> x;
  bool l = false, r = false;
  for (register int i = 0, dif = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (!l) {
        l = true;
        dif = b[i] - a[i];
        if (dif < 0) return cout << "NO\n", 0;
      } else if (a[i] + dif != b[i] or r) {
        return cout << "NO\n", 0;
      }
    } else if (!r) {
      r = true;
    }
  }
  return cout << "YES\n", 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n, cnt = 0, dif = 0;
  cin >> n;
  bool l = false, r = false, ans = true;
  int a[n], b[n];
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] != b[i]) {
      cnt++;
      if (!l) {
        l = true;
        dif = b[i] - a[i];
        if (dif < 0) ans = false;
      } else if (dif != a[i] - b[i]) {
        ans = false;
      }
      if (r) ans = false;
    } else if (l and !r) {
      r = true;
    }
  }
  if (cnt == 1) ans = false;
  cout << ((ans) ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

bool solve() {
  int n;
  cin >> n;
  int a[n];
  for (int &x : a) cin >> x;
  bool l = false, r = false;
  for (int &x : a) {
    int num;
    cin >> num;
    x = num - x;
  }
  for (register int i = 0, dif = 0; i < n; i++) {
    if (a[i] != 0) {
      if (!l) {
        l = true;
        dif = a[i];
      } else if (r or a[i] != dif or a[i] < 0)
        return cout << "NO\n", 0;
    } else if (l and !r)
      r = true;
  }

  return cout << "YES\n", 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

bool solve() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int &x : a) cin >> x;
  for (int &x : b) cin >> x;
  bool l = false, r = false;
  for (register int i = 0, dif = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (!l) {
        l = true;
        dif = b[i] - a[i];
        if (dif < 0) return cout << "NO\n", 0;
      } else if (a[i] + dif != b[i] or r) {
        return cout << "NO\n", 0;
      }
    } else if (l and !r) {
      r = true;
    }
  }
  return cout << "YES\n", 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) {
    int n, cnt = 0, dif = 0;
    cin >> n;
    bool l = false, r = false, ans = true;
    int a[n], b[n];
    for (register int i = 0; i < n; i++) cin >> a[i];
    for (register int i = 0; i < n; i++) {
      cin >> b[i];
      if (a[i] != b[i]) {
        if (!l) {
          l = true;
          dif = b[i] - a[i];
          if (dif < 0) ans = false;
        } else if (a[i] + dif != b[i]) {
          ans = false;
        }
        if (r) ans = false;
      } else if (l and !r) {
        r = true;
      }
    }
    cout << ((ans) ? "YES" : "NO") << "\n";
  }

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n, cnt = 0, dif = 0;
  cin >> n;
  bool l = false, r = false, ans = true;
  int a[n], b[n];
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] != b[i]) {
      cnt++;
      if (!l) {
        l = true;
        dif = b[i] - a[i];
        if (dif < 0) ans = false;
      } else if (dif != b[i] - a[i]) {
        ans = false;
      }
      if (r) ans = false;
    } else if (l and !r) {
      r = true;
    }
  }
  if (cnt == 1) ans = false;
  cout << ((ans) ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  int a[n];
  for (register int i = 0; i < n; i++) cin >> a[i];
  bool ans = true, f = true, chk = false;
  int dif = 0, pos = -1;
  for (register int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (ans) {
      a[i] = a[i] - num;
      if (a[i] != 0) {
        if (f) {
          f = false;
          dif = a[i];
          pos = i;
        } else {
          if (a[i] != dif) ans = false;
          if (chk) ans = false;
        }
      } else if (f == false) {
        chk = true;
        if (pos == i) ans = false;
      }
    }
  }
  if (pos == n - 1) ans = false;
  if (ans) {
    if (pos > 0 and pos < n - 1) {
      if (a[pos - 1] != 0 and a[pos + 1] != 0) ans = false;
    } else if (pos == 0 and a[pos + 1] == 0)
      ans = false;
    else if (pos == n - 1 and a[pos - 1] == 0)
      ans = false;
  }
  std::cout << (ans ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  vector<int> b(n);
  for (int &x : b) cin >> x;
  bool ans = true;
  register int i = 0;
  while (a[i] == b[i] and i < n) i++;
  if (i < n) {
    int pos = i;
    if (pos == n - 1) ans = false;
    if (a[pos + 1] == b[pos + 1]) ans = false;
    int dif = a[i] - b[i];
    i++;
    bool f = true;
    while (i < n and ans) {
      int ndif = a[i] - b[i];
      if (ndif == 0) f = false;
      if (f and ndif != dif) {
        ans = false;
        break;
      }
      if (f == false and a[i] != b[i]) {
        ans = false;
        break;
      }
      i++;
    }
  }
  std::cout << (ans ? "YES" : "NO") << "\n";

  // cout << ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n, cnt = 0, dif = 0;
  cin >> n;
  bool l = false, r = false, ans = true;
  int a[n], b[n];
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] != b[i]) {
      cnt++;
      if (!l) {
        l = true;
        dif = a[i] - b[i];
      } else if (dif != a[i] - b[i]) {
        ans = false;
      }
      if (r) ans = false;
    } else if (l and !r) {
      r = true;
    }
  }
  if (cnt == 1) ans = false;
  cout << ((ans) ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n, cnt = 0;
  cin >> n;
  bool l = false, r = false, ans = true;
  int a[n], b[n];
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < n; i++) {
    cin >> b[i];
    if (a[i] != b[i]) {
      if (!l) l = true;
      cnt++;
      if (r) ans = false;
    } else if (l and !r) {
      r = true;
    }
  }
  if (cnt == 1) ans = false;
  cout << ((ans) ? "YES" : "NO") << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) {
    int n, cnt = 0, dif = 0;
    cin >> n;
    bool l = false, r = false, ans = true;
    int a[n], b[n];
    for (register int i = 0; i < n; i++) cin >> a[i];
    for (register int i = 0; i < n; i++) {
      cin >> b[i];
      if (a[i] != b[i]) {
        cnt++;
        if (!l) {
          l = true;
          dif = b[i] - a[i];
          if (dif < 0) ans = false;
        } else if (a[i] + dif != b[i]) {
          ans = false;
        }
        if (r) ans = false;
      } else if (l and !r) {
        r = true;
      }
    }
    if (cnt == 1) ans = false;
    cout << ((ans) ? "YES" : "NO") << "\n";
  }

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

bool solve() {
  int n;
  cin >> n;
  int a[n];
  for (int &x : a) cin >> x;
  bool l = false, r = false;
  for (int &x : a) {
    int num;
    cin >> num;
    x = num - x;
  }
  for (register int i = 0, dif = 0; i < n; i++) {
    if (a[i] != 0) {
      if (!l) {
        l = true;
        dif = a[i];
        if (dif < 0) return cout << "NO\n", 0;
      } else if (r or a[i] != dif or a[i] < 0)
        return cout << "NO\n", 0;
    } else if (l and !r)
      r = true;
  }

  return cout << "YES\n", 0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#pragma GCC optimization("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define sz(a) a.size()
#define all(a) a.begin(), a.end()
#define w(a) std::cerr << #a << " : " << (a) << "\n";

void solve() {
  int n, cnt = 0, dif = 0;
  cin >> n;
  bool l = false, r = false, ans = true;
  int a[n], num;
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < n; i++) {
    cin >> num;
    if (a[i] != num) {
      if (!l) {
        l = true;
        dif = num - a[i];
        if (dif < 0) ans = false;
      } else if (a[i] + dif != num) {
        ans = false;
      }
      if (r) ans = false;
    } else if (l and !r) {
      r = true;
    }
  }
  cout << ((ans) ? "YES" : "NO") << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  int begtime = clock();
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  register int tc;
  cin >> tc;
  while (tc--) solve();

#ifndef ONLINE_JUDGE
  std::cerr << "\nTime elapsed: " << clock() - begtime << " ms\n\n";
#endif
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<=b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i] && b[i]>a[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if(b[i]<a[i]||(flag1==1 && a[i]!=b[i]))
                {sm=1;k=sm+1;break;}
              //  deb3(flag,flag1,a[i]);
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<=b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll d=0;
            fr(i,0,n)
            {
                if(a[i]>b[i])
                {
                    cout<<"NO\n";flag5=1;break;
                }
                else if(flag==0 && a[i]!=b[i])
                {
                    d=b[i]-a[i];flag=1;
                }
                else if(flag==1 && a[i]!=b[i] && d!=(b[i]-a[i]))
                {
                    cout<<"NO\n";flag5=1;break;
                }
                else if(flag==1 && a[i]==b[i])
                {
                    flag2=1;
                }
                else if(flag2==1 && a[i]!=b[i])
                {
                    cout<<"NO\n";flag5=1;break;
                }
            }
            if(flag5==0)
                cout<<"YES\n";
            flag5=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]==b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if(flag1=1 && a[i]!=b[i] )
                {k=sm+1;break;}
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]==b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i];
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<=b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if(flag1==1 && a[i]!=b[i] )
                {k=sm+1;break;}
              //  deb3(flag,flag1,a[i]);
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i];
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<=b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll d=0;
            fr(i,0,n)
            {
                if(a[i]>b[i])
                {
                    cout<<"NO\n";flag5=1;break;
                }
                else if(flag==0 && a[i]!=b[i])
                {
                    d=b[i]-a[i];flag=1;
                }
                else if(flag==1 && a[i]!=b[i] && d!=(b[i]-a[i]))
                {
                    cout<<"NO\n";flag5=1;break;
                }
                else if(flag==1 && a[i]==b[i])
                {
                    flag2=1;
                }
                else if(flag2==1 && a[i]!=b[i])
                {
                    cout<<"NO\n";flag5=1;break;
                }
            }
            if(flag5==0)
                cout<<"YES\n";
            flag5=0;flag=0;flag1=0;flag2=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<=b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i] && b[i]>a[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if((flag1==1 && a[i]!=b[i])||b[i]<a[i])
                {k=sm+1;break;}
              //  deb3(flag,flag1,a[i]);
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]==b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if(flag1==1 && a[i]!=b[i] )
                {k=sm+1;break;}
              //  deb3(flag,flag1,a[i]);
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]<b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag==1)
                {flag1=1;}
                if(flag1==1 && a[i]!=b[i] )
                {k=sm+1;break;}
              //  deb3(flag,flag1,a[i]);
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)

typedef long long int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

#define PI 3.141592653589793
#define MOD 1000000007

bool flag=0,flag1=0,flag2=0,flag3=0,flag4=0,flag5=0;

int main()
{
    ll t=1;
    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll sm=0;
        vll a(n),b(n);inarr(a,n);inarr(b,n);
        if(n==1)
        {if(a[0]==b[0]) cout<<"YES\n";
        else cout<<"NO\n";}
        else
        {
            ll k=0;
            fr(i,0,n)
            {
                if(a[i]!=b[i])
                    k++,sm+=b[i]-a[i],flag=1;
                if(a[i]==b[i] && flag=1)
                {flag1=1;}
                if(flag1=1 && a[i]!=b[i] )
                {k=sm+1;break;}
            }
            if(k==0||(k!=0 && sm%k==0)) cout<<"YES\n";
            else cout<<"NO\n";
            flag=0;flag1=0;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vi a(n),b(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n)
        cin>>b[i];
    rep(i,n) {
        a[i] = b[i]-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }

    bool flag=true;
    set<int> setty;
    rep(i,n) {
        if(a[i])
            setty.insert(a[i]);
    }
    if(setty.size()>1)
        flag=false;
    cout<< (flag ? "YES" : "NO")<<nl;
}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

const int N = 100100;
int n;
int a[N], b[N];

void solve() {
    cin>>n;

    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
//        if(a[i]<0) {
//            cout<<"NO"<<nl;
//            return;
//        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vi a(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<n&&a[p]==0) p++;
    while(q>=0&&a[q]==0) q--;
    if(p>=q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<n&&a[p]==0) p++;
    while(q>=0&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<n&&a[p]==0) p++;
    while(q>=0&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
//        if(a[i]<0) {
//            cout<<"NO"<<nl;
//            return;
//        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

const int N = 100100;
int n;
int a[N], b[N];

void solve() {
    cin>>n;

    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
//    rep(i,n)
//        cout<<a[i]<<" ";
    bool flag=true;
    int diff=0;
    rep(i,n) {
        if(a[i]==0) {
            continue;
        }
        if(diff==0)
            diff=a[i];
        if(a[i]!=diff) {
            flag=false;
            break;
        }
    }
    cout<< (flag ? "YES" : "NO")<<nl;
}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vi a(n),b(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n)
        cin>>b[i];
    rep(i,n) {
        a[i] = b[i]-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    bool flag=true;
    int diff=0;
    repi(i,1,n) {
        int t = abs(a[i]-a[i-1]);
        if(!t)
            continue;
        if(diff!=0 && t!=diff) {
            flag=false;
            break;
        } else
            diff=t;
    }
    cout<< (flag ? "YES" : "NO")<<nl;
}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n)
        cin>>a[i];
    rep(i,n)
        cin>>b[i];
    rep(i,n) {
        a[i] = b[i]-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }

    bool flag=true;
    set<ll> setty;
    rep(i,n) {
        if(a[i])
            setty.insert(a[i]);
    }
    if(setty.size()>1)
        flag=false;
    cout<< (flag ? "YES" : "NO")<<nl;
}

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

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


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n;
int a[N], b[N];

void solve() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		a[i] = x - a[i];
	}
	int p = 0, q = n - 1;
	while(p <= q && a[p] == 0) p++;
	while(p <= q && a[q] == 0) q--;
	if (p > q) {
		printf("YES\n");
	} else {
		bool ok = a[p] > 0;
		for (int i = p; i <= q; i++)
			ok &= a[i] == a[p];
		if (ok)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int t;
	scanf("%d", &t);
	while(t--) solve();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<int> a(100005);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

int a[100005];
void solve() {
    int n;cin>>n;

    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define repi(i,j,N) for(int (i)=(j);(i)<(N);(i)++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define ll long long
#define numberofdigits(x) floor(log10(x)) + 1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

const char nl = '\n';

void solve() {
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    rep(i,n) {
        int t;cin>>t;
        a[i] = t-a[i];
        if(a[i]<0) {
            cout<<"NO"<<nl;
            return;
        }
    }
    int p=0,q=n-1;
    while(p<=q&&a[p]==0) p++;
    while(p<=q&&a[q]==0) q--;
    if(p>q) {
        cout<<"YES"<<nl;
    } else {
        bool flag = a[p]>0;
        for(int i=p;i<=q;i++) {
            flag &= a[i]==a[p];
        }
        cout<< (flag ? "YES" : "NO")<<nl;
    }

}

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

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


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<n;++i) cin>>b[i];
   set<int>s;
   int c=0;
   if(n==1 )
   {
   	if(a[i]>b[i]) cout<<"NO\n";
   	else cout<<"YES\n";
   	  return;
   }
   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   }
   for(i=0;i<n-1;i++)
   {
   	  for(j=i+1;j<n;++j){
   	  	if(b[j]!=b[i])
   	  	{
   	  		++c;
   	  		break;
   	  	}
   	  }
   	  i=j-1;
   }
   if(c>2)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   for(i=0;i<n;i++)
   {
   	  if(b[i]>0)
   	  {
   	  	for(j=i+1;j<n;j++)
   	  	{
   	  		if(b[j]==0 || b[j]!=b[i] )
   	  		{
   	  			c++;
   	  			break;
   	  		}
   	  	}
   	  	i=j-1;
   	  }

   }
   //cout<<c;
   if(c>=2)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   bool b1=0;
  for(i=0;i<n;i++){
  	if(b[i]>0)
  	{
  		for(j=i;j<n;j++)
  		{
  			if(b[j]==0)
  			{
  			   b1=1;
  			   //break;
  			   break;
  			}
  			else if(b[j]!=b[i])
  			{
  				cout<<"NO\n";
  				return;
  			}
  		}
  		if(b1) break;
  	}
  }
  if(i==n){
  	cout<<"YES\n";
  	return;
  }
  //bool s=0;

  while(j<n)
  {
  	if( b[j]){

  		cout<<"NO\n";
  		return;
  	}
  	++j;
  }
  cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   bool bl=0;
   for(i=0;i<n;i++)
   {
   	  if(b[i]>0 || bl)
   	  {

   	  	for(j=i+1;j<n;j++)
   	  	{
   	  		if(b[j]==0 || b[j]!=b[i] )
   	  		{
   	  			c++;
   	  			bl=1;
   	  			break;
   	  		}
   	  	}
   	  	i=j-1;
   	  }

   }
   //cout<<c;
   if(c>=2)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   bool b1=0;
  for(i=0;i<n;i++){
  	if(b[i]>0)
  	{
  		for(j=i;j<n;j++)
  		{
  			if(b[j]==0)
  			{
  			   b1=1;
  			   //break;
  			   break;
  			}
  			else if(b[j]!=b[i])
  			{
  				cout<<"NO\n";
  				return;
  			}
  		}
  		if(b1) break;
  	}
  }
  if(i==n){
  	cout<<"YES\n";
  	return;
  }
  //bool s=0;

  while(j<n)
  {
  	if(b[j]!=b[i] && b[j]){

  		cout<<"NO\n";
  		return;
  	}
  	++j;
  }
  cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<n;++i) cin>>b[i];
   set<int>s;
   int c=0;
   if(n==1 )
   {
   	if(a[i]>b[i]) cout<<"NO\n";
   	else cout<<"YES\n";
   	  return;
   }
   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   for(i=0;i<n-1;i++)
   {
   	  for(j=i+1;j<n;++j){
   	  	if(b[j]!=b[i])
   	  	{
   	  		++c;
   	  		break;
   	  	}
   	  }
   	  i=j-1;
   }
   if(c>2)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
ll p[1000000]={0};

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

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

  if(n%2)
  {
  	cout<<-1<<'\n';
  	return;
  }

  set<int>s,s1;
  vector<int>v;
  map<int,int>mp;
  for(i=0;i<n;++i)
  {

  	  if(ar[i]>0 ) {
  	  //	p[ar[i]]++;
  	     if(mp[ar[i]]==1 && s.size()!=0)
  	     {
  	     	//cout<<"rr\n";
  	     	cout<<-1;
  	     	return;
  	     }
  	     s.insert(ar[i]);
  	     mp[ar[i]]=1;
  	  }
  	  else
  	  {
  	  	int k=-ar[i];
  	  	if(s.find(k)==s.end())
  	  	{
  	  		//cout<<"r\n";
  	  		cout<<-1;
  	  		return;
  	  	}
  	  	s.erase(k);
  	  	//s1.insert(ar[i]);
  	  }
  	  if(s.size()==0)
  	  {
  	  	  v.pb(i+1);
  	  	  mp.clear();
  	  }

  }
 // cout<<s.size()<<'\n';
  if(s.size())
  {
  	cout<<-1;
  	return;
  }
 // for(auto x:v) cout<<x<<' ';
 cout<<v.size()<<'\n';
 cout<<v[0]<<' ';
 for(i=1;i<v.size();i++)
 cout<<v[i]-v[i-1]<<' ';

}

int main()
{
	fast;
	int t=1;
     //cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   bool b1=0;
  for(i=0;i<n;i++){
  	if(b[i]>0)
  	{
  		for(j=i+1;j<n;j++)
  		{
  			if(b[j]==0)
  			{
  			   b1=1;
  			   //break;
  			   break;
  			}
  			else if(b[j]!=b[i])
  			{
  				cout<<"NO\n";
  				return;
  			}
  		}
  		if(b1) break;
  	}
  }
  //bool s=0;
  while(j<n)
  {
  	if(b[j]!=b[i] || b[j]){

  		cout<<"NO\n";
  		return;
  	}
  	++j;
  }
  cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

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

   for(i=0;i<n;i++)
   {
   	  int k=a[i]-b[i];
   	  if(k>0){
   	  	cout<<"NO\n";
   	  	return;
   	  }
   	  else if(k<0) s.insert(k);

   }
   if(s.size()>1)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) cin>>a[i];
   for(i=0;i<n;++i) cin>>b[i];
   set<int>s;
   int c=0;
   if(n==1 )
   {
   	if(a[0]>b[0]) cout<<"NO\n";
   	else cout<<"YES\n";
   	  return;
   }
   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   for(i=0;i<n-1;i++)
   {
   	  for(j=i+1;j<n;++j){
   	  	if(b[j]!=b[i])
   	  	{
   	  		++c;
   	  		break;
   	  	}
   	  }
   	  i=j-1;
   }
   if(c>2)
   {
   	cout<<"NO\n";
   	return;
   }
   cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
ll mod=1e9+7;
//ll ar[500001];

bool comp(ll a,ll b)
{
	return (a<b);
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b%2==0) return power(a*a,b/2);
	else return a*power(a*a,(b-1)/2);
}

void solve()
{
   int n,i,j;
   cin>>n;
   int a[n],b[n];
   for(i=0;i<n;i++) {cin>>a[i];}
   for(i=0;i<n;i++) {cin>>b[i];}
   //s//et<int>s;
   int c=0;

   for(i=0;i<n;i++)
   {
   	  b[i]-=a[i];
   	  if(b[i]<0)
   	  {
   	  	cout<<"NO\n";
   	  	return;
   	  }
   }
   bool b1=0;
  for(i=0;i<n;i++){
  	if(b[i]>0)
  	{
  		for(j=i;j<n;j++)
  		{
  			if(b[j]==0)
  			{
  			   b1=1;
  			   //break;
  			   break;
  			}
  			else if(b[j]!=b[i])
  			{
  				cout<<"NO\n";
  				return;
  			}
  		}
  		if(j==n){
  			cout<<"YES\n";
  			return;
  		}
  		if(b1) break;
  	}
  }
  if(i==n){
  	cout<<"YES\n";
  	return;
  }
  //bool s=0;

  while(j<n)
  {
  	if( b[j]){

  		cout<<"NO\n";
  		return;
  	}
  	++j;
  }
  cout<<"YES\n";
}

int main()
{
	fast;
	int t=1;
     cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i < n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] <= 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

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

    }
    bool f =true;
    int k = 0;
    for (int i = 0; i < n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f== true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

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

    }
    bool f =true;
    int k = 0;
    for (int i = 0; i < n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>

using namespace std;

int main (){
    int t,n;
    int ans[t];
    cin >> n;
    for(int i = 0; i < t;i++){
        cin >> t;
        int a_1[n];
        int a_2[n];
        int a_3[n];
        int k = 0;
        int l = 0;
        for (int y = 0; y < n;i++){
            cin >> a_1[y] ;

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

        }
        for (int y = 0; y < n;i++){
          if(a_2[y]!= a_1[y]){
            a_3[y] =  a_2[y] - a_1[y];
            k++;
          }
        }
        for (int y = 0; y < k;i++){
            if(a_3[y] == a_3[y+1]){
                l++;
            }

        }
        if(l == k){
            ans[i] = 1;
        }else{
            ans[i] = 0;
        }

    }

    for (int i = 0; i < t; i++){
        if(ans[i] == 1){
            cout <<"YES\n";
        }else{
            cout <<"NO\n";
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i < n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}
close


#include <iostream>
 #include <cmath>

using namespace std;

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i < n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }

        if( f == true && k <= 2){
            cout << "YES"<< endl;
        }else{
             cout << "NO"<< endl;
        }

    }

    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

int main (){

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n+1; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }
    }
        if( f == true && k <= 2)
            cout << "YES"<< endl;
        else
             cout << "NO"<< endl;

}
    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

int main (){

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }
    }
        if( f == true && k == 1 || k == 2 && a[n] == 0)
            cout << "YES"<< endl;
        else
             cout << "NO"<< endl;

}
    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

int main (){
    int a[10000] = {};
    int t ;
    cin >> t;
    while(t--){

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }
    }
        if( f == true && k <= 2)
            cout << "YES"<< endl;
        else
             cout << "NO"<< endl;

}
    return 0;
}


#include <iostream>
 #include <cmath>

using namespace std;

int main (){
    int a[100005] = {};
    int t ;
    cin >> t;
    while(t--){

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

    for (int i = 1; i <= n; i++){
        int x;
        cin >> x;
        a[i] = x- a[i];

    }
    bool f =true;
    int k = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] < 0){
        f = false;
        }
        if(a[i] != a[i-1]){
            k++;
        }
    }
        if( f == true && k <= 2)
            cout << "YES"<< endl;
        else
             cout << "NO"<< endl;

}
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

bool solve(int n ,int  c[] )
{
    int cnt=0;
    if(n==1)
    {
        if(c[0]<0)
        {
            return false;
        }
    }
    else
    for(int i=1;i<n;i++)
    {
        if(c[i]!=c[i-1])
        {
            cnt++;
        }
        if(c[i]<0)
        {
            return false;
        }
    }
    if(cnt<=2)
    {
        return true;
    }
    return false;
}

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n] ;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
       }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
       bool ans=solve(n, c);
        if(ans)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
         }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
        ll n;
        cin>>n;
        int  flag=0 , a[m]={0} , b[m]={0} , c[m]={0};
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            if(c[i]!=c[i-1])
            {
                cnt++;
            }
            if(c[i]<0)
            {
                flag=1;
            }
        }
        if(flag==1 || cnt>2)
        {
            cout<<"NO"<<endl;
        }
        else if(cnt<=2)
        {
            cout<<"YES"<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
    ll n;
    cin>>n;
    int a[n] , b[n] , c[n] , flag=0 , cnt=0;
    repi(i , n)
    {
        cin>>a[i];
    }
    repi(i , n)
    {
        cin>>b[i];
        c[i]=a[i]-b[i];
    }
   for(int i=1;i<n;i++)
   {
       if(c[i]<0)
       {
           flag=1;
       }
       if(c[i]!=c[i-1])
       {
           cnt++;
       }
   }
   if(n==1)
   {
       if(a[0]-b[0]<0)
       {
           cout<<"NO"<<endl;
       }

       else

       cout<<"YES"<<endl;

   }
  else if(cnt<=2)
   {
       cout<<"YES"<<endl;
   }

   else
   {
       cout<<"NO"<<endl;
   }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

bool solve(int n ,int  c[] )
{

    int cnt=0;
    if(n==1)
    {
        if(c[1]<0)
        {
            return false;
        }
    }
    else
    for(int i=1;i<=n+1;i++)
    {
        if(c[i]!=c[i-1])
        {
            cnt++;
        }
        if(c[i]<0)
        {
            return false;
        }
    }
    if(cnt<=2)
    {
        return true;
    }
    return false;
}

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n+2]={0} ;
       for(int i=1;i<=n;i++)
       {
           cin>>a[i];
       }

        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
       bool ans=solve(n, c);
        if(ans)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
         }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
    ll n;
    cin>>n;
    int a[n] , b[n] , c[n] , flag=0 , cnt=0;
    repi(i , n)
    {
        cin>>a[i];
    }
    repi(i , n)
    {
        cin>>b[i];
        c[i]=a[i]-b[i];
    }
   for(int i=1;i<n;i++)
   {
       if(c[i]<0)
       {
           flag=1;
       }
       if(c[i]!=c[i-1])
       {
           cnt++;
       }
   }
   if(n==1)
   {
       if(b[0]-a[0]<0)
       {
           cout<<"NO"<<endl;
       }

   }
  else if(cnt<=2)
   {
       cout<<"YES"<<endl;
   }

   else if(cnt>2)
   {
       cout<<"NO"<<endl;
   }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

bool solve(int n ,int  c[] )
{

    int cnt=0;
    if(n==1)
    {
        if(c[1]<0)
        {
            return false;
        }
    }
    else
    for(int i=1;i<=n;i++)
    {
        if(c[i]!=c[i-1])
        {
            cnt++;
        }
        if(c[i]<0)
        {
            return false;
        }
    }
    if(cnt<=2)
    {
        return true;
    }
    return false;
}

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n+2]={0} ;
       for(int i=1;i<=n;i++)
       {
           cin>>a[i];
       }

        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
       bool ans=solve(n, c);
        if(ans)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
         }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n] , cnt=0 , flag=0;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
       }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }

        for(int i=1;i<n;i++)
        {
            if(c[i]!=c[i-1])
            {
                cnt++;
            }
            if(c[i]<0)
            {
                flag=2;
            }
        }
        if(cnt<=2 && flag==0 && n!=1)
        {
            cout<<"YES"<<endl;
        }
        else if(flag==2)
        {cout<<"NO"<<endl;}
        else{cout<<"NO"<<endl;}
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

bool solve(int n ,int  c[] )
{

    int cnt=0;
    if(n==1)
    {
        if(c[1]<0)
        {
            return false;
        }
    }
    else
    for(int i=1;i<=n-1;i++)
    {
        if(c[i]!=c[i-1])
        {
            cnt++;
        }
        if(c[i]<0)
        {
            return false;
        }
    }
    if(cnt<=2)
    {
        return true;
    }
    return false;
}

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n+2]={0} ;
       for(int i=1;i<=n;i++)
       {
           cin>>a[i];
       }

        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
       bool ans=solve(n, c);
        if(ans)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
         }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
        ll n;
        cin>>n;
        int m=n+2 , flag=0 , a[m]={0} , b[m]={0} , c[m]={0};
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
        int cnt=0;
        for(int i=0;i<m;i++)
        {
            if(c[i]!=c[i+1])
            {
                cnt++;
            }
            if(c[i]<0)
            {
                flag=1;
            }
        }
        if(flag==1 || cnt>2)
        {
            cout<<"NO"<<endl;
        }
        else if(cnt<=2)
        {
            cout<<"YES"<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define repi(i,n) for (int i = 0; i <n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
#define INT_MAX 2147483647
#define joshi main

using namespace std;

int joshi()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);//for input from input.txt
// 	freopen("output.txt", "w", stdout); //for Output.txt
// #endif
int test_case;
cin>>test_case;
while(test_case--)
{
ll n;cin>>n;
int a[n] , b[n] , h[n];

repi(i , n)
{
    cin>>a[i];
}
repi(i , n)
{
    cin>>b[i];
    h[i]=b[i]-a[i];
}
 ll cnt=0 , flag=0;
for(int i=1;i<n;i++)
{
    if(h[i]!=h[i-1])
    {
        cnt++;
    }
    if(h[i]<0)
    {
        flag=1;
        break;
    }

}
if(n==1)
{
    if(b[0]-a[0]<0)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }
}
else if(cnt<=2 && flag!=1)
{
    cout<<"YES"<<endl;
}
else
{
    cout<<"NO"<<endl;
}

}
return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define repi(i,n) for (int i = 0; i <n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
#define INT_MAX 2147483647
#define joshi main

using namespace std;

int solve(int h[] , int n)
{
    ll cnt=0 , flag=0;
for(int i=1;i<n;i++)
{
    if(h[i]!=h[i-1])
    {
        cnt++;
    }
    if(h[i]<0)
    {
       return 1;
    }

}
if(n==1)
{
    if(h[0]<0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

else if(n==3)
{
    if(cnt<=1)
    {
        return 0;
    }
    else
    return 1;
}
else if(cnt<=2 && flag!=1)
{
    return 0;
}
else
{
return 1;
}
}
int joshi()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);//for input from input.txt
// 	freopen("output.txt", "w", stdout); //for Output.txt
// #endif
int test_case;
cin>>test_case;
while(test_case--)
{
ll n;cin>>n;
int a[n] , b[n] , h[n];

repi(i , n)
{
    cin>>a[i];
}
repi(i , n)
{
    cin>>b[i];
    h[i]=b[i]-a[i];
}
int x=solve(h , n);
if(x==0)
{
    cout<<"YES"<<endl;
}
else
{
    cout<<"NO"<<endl;
}

}
return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
        ll n;
        cin>>n;
        int m=n+2 , flag=0 , a[m]={0} , b[m]={0} , c[m]={0};
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=1;i<=n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
        int cnt=0;
        for(int i=0;i<m;i++)
        {
            if(c[i]!=c[i+1])
            {
                cnt++;
            }
            if(c[i]<0)
            {
                flag=1;
            }
        }
        if(flag==1 || cnt>2)
        {
            cout<<"NO"<<endl;
        }
        else if(cnt<=2)
        {
            cout<<"YES"<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define repi(i,n) for (int i = 0; i < n; i++)
#define repione(i,n) for (int i = 1; i <=n; i++)
#define repj(j,n) for (int j = 0; j < n; j++)
#define repjone(j,n) for (int j = 1; j <=n; j++)
#define endl '\n'
#define vi vector<int>
#define pi pair<int, int>
#define pb(a) push_back(a)
using namespace std;

bool solve(int n ,int  c[] )
{
    int cnt=0;
    if(n==1)
    {
        if(c[0]<0)
        {
            return false;
        }
    }
    else
    for(int i=1;i<n;i++)
    {
        if(c[i]!=c[i-1])
        {
            cnt++;
        }
        if(c[i]<0)
        {
            return false;
        }
    }
    if(cnt<=2 && n>3)
    {
        return true;
    }
    return false;
}

int main()
{
    ll test_case;
    cin>>test_case;
    while(test_case--)
    {
       ll n;
       cin>>n;
       int a[n] , b[n] , c[n] ;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
       }
        for(int i=0;i<n;i++)
        {
            cin>>b[i];
            c[i]=b[i]-a[i];
        }
       bool ans=solve(n, c);
        if(ans)
        {
            cout<<"YES"<<endl;
        }
        else
        cout<<"NO"<<endl;
         }
    return 0;
}