#include <bits/stdc++.h>

using namespace std;

const int inf = 2e9;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    vector<int> p(k), x(k);
    for (int i = 0; i < k; ++i) cin >> p[i];
    for (int i = 0; i < k; ++i) cin >> x[i];
    vector<int> a(n);
    for (int i = 0; i < k; ++i) a[p[i]-1] = x[i];

    vector<int> l(n, inf);
    {
      int j = 0;
      while (a[j] == 0) j++;
      int mn = inf, t = 0;
      for (int i = j; i < n; ++i) {
        if (a[i]) mn = min(mn, a[i] - t);
        l[i] = mn + t;
        t++;
      }
    }
    vector<int> r(n, inf);
    {
      int j = n - 1;
      while (a[j] == 0) j--;
      int mn = inf, t = 0;
      for (int i = j; i >= 0; --i) {
        if (a[i]) mn = min(mn, a[i] - t);
        r[i] = mn + t;
        t++;
      }
    }
    for (int i = 0; i < n; ++i) {
      cout << min(l[i], r[i]) << ' ';
    }
    cout << '\n';
  }
  return 0;
}
