You are given two arrays of integers a_1, a_2, …, a_n and b_1, b_2, …, b_m.

You need to insert all elements of b into a in an arbitrary way. As a result you will get an array c_1, c_2, …, c_{n+m} of size n + m.

Note that you are not allowed to change the order of elements in a, while you can insert elements of b at arbitrary positions. They can be inserted at the beginning, between any elements of a, or at the end. Moreover, elements of b can appear in the resulting array in any order.

What is the minimum possible number of inversions in the resulting array c? Recall that an inversion is a pair of indices (i, j) such that i < j and c_i > c_j.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10^4). Description of the test cases follows.

The first line of each test case contains two integers n and m (1 ≤ n, m ≤ 10^6).

The second line of each test case contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9).

The third line of each test case contains m integers b_1, b_2, …, b_m (1 ≤ b_i ≤ 10^9).

It is guaranteed that the sum of n for all tests cases in one input doesn't exceed 10^6. The sum of m for all tests cases doesn't exceed 10^6 as well.

Output

For each test case, print one integer — the minimum possible number of inversions in the resulting array c.

Example

Input


3
3 4
1 2 3
4 3 2 1
3 3
3 2 1
1 2 3
5 4
1 3 5 3 1
4 3 6 1


Output


0
4
6

Note

Below is given the solution to get the optimal answer for each of the example test cases (elements of a are underscored).

  * In the first test case, c = [\underline{1}, 1, \underline{2}, 2, \underline{3}, 3, 4]. 
  * In the second test case, c = [1, 2, \underline{3}, \underline{2}, \underline{1}, 3]. 
  * In the third test case, c = [\underline{1}, 1, 3, \underline{3}, \underline{5}, \underline{3}, \underline{1}, 4, 6]. 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void fileio(const string &s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const long long INF = 4e18;
inline long long read() {
  long long x = 0;
  bool flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return (flag ? x : ~(x - 1));
}
long long T, n, m, cnt, root, tot, a[1000001], b[1000001], L[2000001],
    R[2000001], tag[2000001], t1[2000001];
array<long long, 2> t[2000001], aa[1000001], c[2000001];
void push_up(long long x) {
  if (t[L[x]][0] < t[R[x]][0])
    t[x] = t[L[x]];
  else
    t[x] = t[R[x]];
}
void build(long long &x, long long l, long long r) {
  if (!x) x = ++cnt;
  if (l == r) {
    t[x] = {l, l};
    return;
  }
  long long mid = (l + r) >> 1;
  build(L[x], l, mid);
  build(R[x], mid + 1, r);
  push_up(x);
}
void push_down(long long x) {
  long long k = tag[x];
  tag[x] = 0;
  t[L[x]][0] += k;
  t[R[x]][0] += k;
  tag[L[x]] += k;
  tag[R[x]] += k;
}
void modify(long long x, long long l, long long r, long long ll, long long rr,
            long long k) {
  if (l >= ll && r <= rr) {
    t[x][0] += k;
    tag[x] += k;
    return;
  }
  push_down(x);
  long long mid = (l + r) >> 1;
  if (ll <= mid) modify(L[x], l, mid, ll, rr, k);
  if (rr > mid) modify(R[x], mid + 1, r, ll, rr, k);
  push_up(x);
}
long long lowbit(long long x) { return x & (-x); }
void add(long long x) {
  for (; x <= tot; x += lowbit(x)) t1[x]++;
}
long long ask(long long x) {
  long long res = 0;
  for (; x; x -= lowbit(x)) res += t1[x];
  return res;
}
long long idx;
bool cmp(array<long long, 2> x, array<long long, 2> y) { return x[1] < y[1]; }
void solve() {
  n = read();
  m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= m; i++) b[i] = read();
  sort(b + 1, b + 1 + m);
  for (long long i = 1; i <= n; i++) aa[i] = {a[i], i};
  sort(aa + 1, aa + 1 + n);
  fill(L + 1, L + 1 + 2 * n, 0);
  fill(R + 1, R + 1 + 2 * n, 0);
  fill(tag + 1, tag + 1 + 2 * n, 0);
  root = tot = cnt = 0;
  build(root, 1, n);
  long long lst = 0;
  for (long long i = 1, l = 1; i <= m; i++) {
    while (l <= n && aa[l][0] <= b[i]) {
      modify(root, 1, n, aa[l][1], n, -2);
      l++;
    }
    array<long long, 2> q = t[root];
    if (q[0] > 0) q = {0, 0};
    for (long long j = lst + 1; j <= q[1]; j++) c[++tot][0] = a[j];
    c[++tot][0] = b[i];
    lst = q[1];
  }
  for (long long i = lst + 1; i <= n; i++) c[++tot][0] = a[i];
  for (long long i = 1; i <= tot; i++) c[i][1] = i;
  idx = 0;
  sort(c + 1, c + 1 + tot);
  for (long long i = 1; i <= tot; i++) {
    if (c[i][0] != c[i - 1][0]) idx++;
    c[i][0] = idx;
  }
  sort(c + 1, c + 1 + tot, cmp);
  long long ans = 0;
  fill(t1, t1 + 1 + tot, 0);
  for (long long i = tot; i >= 1; i--) {
    ans += ask(c[i][0] - 1);
    add(c[i][0]);
  }
  cout << ans << endl;
}
signed main() {
  T = read();
  while (T--) solve();
  return 0;
}
