#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int N = 3e5 + 10;
const int inf = 0x3f3f3f3f;
int a[N];
int t[N];
int ans[N];
int main()
{
	int T;
	cin >> T;
	int n,k;
	while (T--)
	{
		scanf("%d%d",&n,&k);
		for(int i = 0;i <= n;i ++)
        {
            ans[i] = t[i] = inf;
        }
        for(int i = 1;i <= k;i ++)scanf("%d",a+i);
        for(int i = 1;i <= k;i ++)scanf("%d",&t[a[i]]);
        int tmp = inf;
        for(int i = 1;i <= n;i ++)
        {
            tmp = min(tmp,t[i]);
            ans[i] = min(ans[i],tmp++);
        }
        tmp = inf;
        for(int i = n;i > 0;i --)
        {
            tmp = min(tmp,t[i]);
            ans[i] = min(ans[i],tmp++);
        }
        for(int i = 1;i <= n;i ++)
            printf("%d%c",ans[i],i==n?'\n':' ');

	}
}


