#include #include #include #include #include #include #include using namespace std; const int mx=100005; long long b[mx],c[mx]; int main() { int t; scanf("%d",&t); while (t--) { int n; scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%I64d",&b[i]); for (int i=1;i<=n;i++) scanf("%I64d",&c[i]); if (b[1]!=c[1]) { printf("0\n"); continue; } long long ans=1; for (int i=2;i<=n;i++) { if (b[i]>b[i-1]||c[i]c[i-1])) { ans=0; break; } if (c[i]-b[i]+1