#include<bits/stdc++.h>
#define Fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
    Fast;
    int q , n , k ,a , b;
    cin>>q;
    while(q--){
        cin>>n>>k;
        int right[300001] , left[300001];
        fill(right , right+n , 2e9);
        fill(left , left+n , 2e9);
        int arr[300001] ;
        for(int i=0;i<k;i++)    cin>>arr[i];
        for(int i=0;i<k;i++)    cin>>a , b = arr[i] -1 , left[b] = a , right[b] = a;
        int x = 2e9;
        for(int i=0;i<n;i++){
            if(right[i] != 2e9){
                x = min(x , right[i]);
            }
            if(x != 2e9){
                right[i] = x;
                x++;
            }
        }
        x = 2e9;
        for(int i=n-1;i>=0;i--){
            if(left[i] != 2e9){
                x = min(x , left[i]);
            }
            if(x !=2e9){
                left[i] = x;
                x++;
            }
        }
       for(int i=0;i<n;i++){
            cout<<min(left[i] , right[i])<<" ";
        }
        cout<<endl;
    }
    return 0;
}