using System;

namespace ConsoleApp1
{
    internal class Program
    {
        static bool proveriIspravnost(int[] a, int[] b)
        {
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] != b[i])
                {
                    Console.WriteLine("Brojevi {0} i {1} su nejednaki", a[i], b[i]);
                    return false;
                }
            }
            return true;
        }
        static void razmeni(ref int a, ref int b)
        {
            int p = a * (-1);
            a = b * (-1);
            b = p;
        }
        static void provera(ref int[] a, int[] b, int i, int n)
        {
            if (i >= n) return;
            else
            {
                razmeni(ref a[i - 1], ref a[i]);
                if (a[i] != b[i] && a[i - 1] != b[i - 1])
                {
                    provera(ref a, b, i + 1, n);
                }
            }
            return;
        }

        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            bool[] resenja = new bool[t];

            for(int i = 0; i < t; i++)
            {
                int n = int.Parse(Console.ReadLine());
                string[] str = Console.ReadLine().Split();
                int[] a = new int[n];
                for(int j = 0; j < n; j++)
                {
                    a[j] = int.Parse(str[j]);
                }
                str = Console.ReadLine().Split();
                int[] b = new int[n];

                for (int j = 0; j < n; j++)
                {
                    b[j] = int.Parse(str[j]);
                }


                provera(ref a, b, 1, n);

                Console.WriteLine();
                foreach (int x in a)
                {
                    Console.Write(x + " ");
                }
                Console.WriteLine();

                Console.WriteLine();
                foreach (int x in a)
                {
                    Console.Write(x + " ");
                }
                Console.WriteLine();

                resenja[i] = proveriIspravnost(a, b);


                Console.WriteLine("Jednakost a i b {0}",proveriIspravnost(a, b));
            }
            
            foreach(bool x in resenja)
            {
                if(x)
                {
                    Console.WriteLine("DA");
                }
                else
                {
                    Console.WriteLine("NE");
                }
            }
            
        }
    }
}