t = int(input())
while t > 0:
n = int(input())
arrA = list(map(int, input().split(' ')))
arrB = list(map(int, input().split(' ')))
taken = False
diff = 0
i = 0
count = 0
while i < n:
if arrB[i] != arrA[i]:
count += 1
while i < n and (not taken or arrB[i]-arrA[i] == diff):
diff = arrB[i]-arrA[i]
if diff < 0:
count = 5
taken = True
i += 1
if i < n and arrB[i] != arrA[i]:
count = 4
i += 1
if count >= 2:
print("NO")
else:
print("YES")
t -= 1
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <random>
#include<bits/stdc++.h>
using namespace std;
// const int N = 1e5+10;
#define ll long long;
const int M = 1e9+7;
#define tc int t; cin >> t; while(t--)
int main(){
tc{
int n;
cin>>n;
int a[n];
int b[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int j = 0; j < n; j++){
cin>>b[j];
}
int c[n];
for(int i=0;i<n;i++){
c[i] = (b[i] - a[i]);
}
int cnt = 0;
for(int i=0;i<n;i++){
if(c[i] != 0 && c[i] != c[i-1]){
if(c[i] > 0){
cnt++;
}
else{
cnt = 2;
}
}
}
if(cnt > 1){
cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
}
1585B - Array Eversion | 1661C - Water the Trees |
1459A - Red-Blue Shuffle | 1661B - Getting Zero |
1661A - Array Balancing | 1649B - Game of Ball Passing |
572A - Arrays | 1455A - Strange Functions |
1566B - MIN-MEX Cut | 678C - Joty and Chocolate |
1352E - Special Elements | 1520E - Arranging The Sheep |
1157E - Minimum Array | 1661D - Progressions Covering |
262A - Roma and Lucky Numbers | 1634B - Fortune Telling |
1358A - Park Lighting | 253C - Text Editor |
365B - The Fibonacci Segment | 75A - Life Without Zeros |
1519A - Red and Blue Beans | 466A - Cheap Travel |
659E - New Reform | 1385B - Restore the Permutation by Merger |
706A - Beru-taxi | 686A - Free Ice Cream |
1358D - The Best Vacation | 1620B - Triangles on a Rectangle |
999C - Alphabetic Removals | 1634C - OKEA |