// Generated by CoffeeScript 2.4.1
var N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint, range,
  indexOf = [].indexOf;

print = console.log;

process.stdin.resume();

process.stdin.setEncoding('utf-8');

inputString = '';

currentLine = 0;

process.stdin.on('data', function(inputStdin) {
  return inputString += inputStdin;
});

process.stdin.on('end', function(_) {
  inputString = inputString.trim().split('\n').map(function(string) {
    return string.trim();
  });
  return main();
});

input = function() {
  return inputString[currentLine++];
};

nr = function() {
  return parseInt(input());
};

nrs = function() {
  var i, k, len, ref, results;
  ref = input().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

range = function(start, stop, step) {
  var i, k, length, ref, ref1, ref2, results;
  if (stop === void 0) {
    stop = start || 0;
    start = 0;
  }
  if (step === void 0) {
    step = stop < start ? -1 : 1;
  }
  length = Math.max(Math.ceil((stop - start) / step), 0);
  results = [];
  for (i = k = ref = start, ref1 = start + length, ref2 = step; ref2 !== 0 && (ref2 > 0 ? k < ref1 : k > ref1); i = k += ref2) {
    results.push(i);
  }
  return results;
};

//##################################################
N = 3162;

p2 = [];

randint = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

prepare = function() {
  var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;
  p = (function() {
    var k, len, ref, results;
    ref = range(N);
    results = [];
    for (k = 0, len = ref.length; k < len; k++) {
      i = ref[k];
      results.push(1);
    }
    return results;
  })();
  ref = range(2, N);
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    if (p[i]) {
      ref1 = range(2 * i, N, i);
      for (l = 0, len1 = ref1.length; l < len1; l++) {
        j = ref1[l];
        p[j] = 0;
      }
    }
  }
  ref2 = range(2, N);
  results = [];
  for (m = 0, len2 = ref2.length; m < len2; m++) {
    c = ref2[m];
    if (p[c] === 1) {
      results.push(c * c);
    }
  }
  return results;
};

f = function(a) {
  var ans, hash, k, kl, l, len, len1, q, r, r0;
  ans = 1;
  kl = {};
  hash = {};
  for (k = 0, len = a.length; k < len; k++) {
    r0 = a[k];
    if (indexOf.call(hash, r0) >= 0) {
      r = hash[r0];
    } else {
      r = r0;
      for (l = 0, len1 = p2.length; l < len1; l++) {
        q = p2[l];
        if (r < q) {
          break;
        }
        while (r % q === 0) {
          r = Math.floor(r / q);
        }
      }
      hash[r0] = r;
    }
    if (r in kl) {
      ans += 1;
      kl = {};
    }
    kl[r] = 1;
  }
  return ans;
};

main = function() {
  var _, k, len, ref, results;
  p2 = prepare();
  ref = range(nr());
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    _ = ref[k];
    [_, _] = nrs();
    results.push(print(f(nrs())));
  }
  return results;
};

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLEtBQUEsRUFBQSxPQUFBLEVBQUEsS0FBQTtFQUFBOztBQUFBLEtBQUEsR0FBUSxPQUFPLENBQUM7O0FBRWhCLE9BQU8sQ0FBQyxLQUFLLENBQUMsTUFBZCxDQUFBOztBQUNBLE9BQU8sQ0FBQyxLQUFLLENBQUMsV0FBZCxDQUEwQixPQUExQjs7QUFFQSxXQUFBLEdBQWM7O0FBQ2QsV0FBQSxHQUFjOztBQUVkLE9BQU8sQ0FBQyxLQUFLLENBQUMsRUFBZCxDQUFpQixNQUFqQixFQUF5QixRQUFBLENBQUMsVUFBRCxDQUFBO1NBQWdCLFdBQUEsSUFBZTtBQUEvQixDQUF6Qjs7QUFFQSxPQ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MjIyMjIyMjIyMjIyMjIyNcblxuTiA9IDMxNjJcbnAyID0gW11cblxucmFuZGludCA9IChtaW4sIG1heCkgLT4gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogKG1heCAtIG1pbiArIDEpICkgKyBtaW5cblxucHJlcGFyZSA9ICgpIC0+XG5cdHAgPSAoMSBmb3IgaSBpbiByYW5nZSBOKVxuXHRmb3IgaSBpbiByYW5nZSAyLE5cblx0XHRpZiBwW2ldXG5cdFx0XHRmb3IgaiBpbiByYW5nZSAyKmksTixpXG5cdFx0XHRcdHBbal0gPSAwXG5cdGMqYyBmb3IgYyBpbiByYW5nZSAyLE4gd2hlbiBwW2NdPT0xXG5cbmYgPSAoYSkgLT5cblx0YW5zID0gMVxuXHRrbCA9IHt9XG5cdGhhc2ggPSB7fVxuXHRmb3IgcjAgaW4gYVxuXHRcdGlmIHIwIGluIGhhc2hcblx0XHRcdHIgPSBoYXNoW3IwXVxuXHRcdGVsc2Vcblx0XHRcdHIgPSByMFxuXHRcdFx0Zm9yIHEgaW4gcDJcblx0XHRcdFx0aWYgciA8IHFcblx0XHRcdFx0XHRicmVha1xuXHRcdFx0XHR3aGlsZSByICUgcSA9PSAwXG5cdFx0XHRcdFx0ciAvLz0gcVxuXHRcdFx0aGFzaFtyMF09clxuXHRcdGlmIHIgb2Yga2xcblx0XHRcdGFucyArPSAxXG5cdFx0XHRrbCA9IHt9XG5cdFx0a2xbcl0gPSAxXG5cdGFuc1xuXG5tYWluID0gLT5cblx0cDIgPSBwcmVwYXJlKClcblx0Zm9yIF8gaW4gcmFuZ2UgbnIoKVxuXHRcdFtfLF9dID0gbnJzKClcblx0XHRwcmludCBmIG5ycygpXG4iXX0=
//# sourceURL=c:\github\2021\010\coffee\app.coffee

// Generated by CoffeeScript 2.4.1
var A, K, N, _, a, dp, i, j, k, l, len, len1, len2, m, min, n, nr, nrs, o, p, q, ref, ref1, ref2, sq, squares, used, xxx;

nrs = function() {
  var i, k, len, ref, results;
  ref = readline().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

nr = function() {
  return nrs()[0];
};

function range(start, stop, step) {
  if (stop == null) {
    stop = start || 0
    start = 0
  }
  if (!step) step = stop < start ? -1 : 1

  var length = Math.max(Math.ceil((stop - start) / step), 0)
  var range = Array(length)

  for (var idx = 0; idx < length; idx++, start += step) range[idx] = start

  return range;
}
;

min = function(lst) {
  var best, item, k, len;
  best = lst[0];
  for (k = 0, len = lst.length; k < len; k++) {
    item = lst[k];
    best = item < best ? item : best;
  }
  return best;
};

n = 10000000;

squares = (function() {
  var k, results;
  results = [];
  for (i = k = 1; k < 3162; i = ++k) {
    results.push(i * i);
  }
  return results;
})();

p = (function() {
  var k, ref, results;
  results = [];
  for (i = k = 0, ref = n + 1; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {
    results.push(i);
  }
  return results;
})();

for (i = k = 1, ref = n + 1; (1 <= ref ? k < ref : k > ref); i = 1 <= ref ? ++k : --k) {
  if (p[i] === i) {
    for (l = 0, len = squares.length; l < len; l++) {
      sq = squares[l];
      if (i * sq > n) {
        break;
      }
      p[i * sq] = i;
    }
  }
}

for (_ = m = 0, ref1 = nr(); (0 <= ref1 ? m < ref1 : m > ref1); _ = 0 <= ref1 ? ++m : --m) {
  xxx = nrs();
  N = xxx[0];
  K = xxx[1];
  A = (function() {
    var len1, o, ref2, results;
    ref2 = nrs();
    results = [];
    for (o = 0, len1 = ref2.length; o < len1; o++) {
      a = ref2[o];
      results.push(p[a]);
    }
    return results;
  })();
  dp = (function() {
    var len1, o, ref2, results;
    ref2 = range(K + 1);
    results = [];
    for (o = 0, len1 = ref2.length; o < len1; o++) {
      _ = ref2[o];
      results.push(N);
    }
    return results;
  })();
  dp[0] = 1;
  used = (function() {
    var o, ref2, results;
    results = [];
    for (_ = o = 0, ref2 = K + 1; (0 <= ref2 ? o < ref2 : o > ref2); _ = 0 <= ref2 ? ++o : --o) {
      results.push({});
    }
    return results;
  })();
  for (o = 0, len1 = A.length; o < len1; o++) {
    a = A[o];
    ref2 = range(K, -1, -1);
    for (q = 0, len2 = ref2.length; q < len2; q++) {
      j = ref2[q];
      if (dp[j] === N) {
        continue;
      }
      if (a in used[j]) {
        if (j < K && dp[j + 1] > dp[j]) {
          dp[j + 1] = dp[j];
          used[j + 1] = used[j];
        }
        dp[j] += 1;
        used[j] = {};
      }
      used[j][a] = 1;
    }
  }
  print(min(dp));
}

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamltbTg5LmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGppbW04OS5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxFQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxJQUFBLEVBQUEsSUFBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLEVBQUEsRUFBQSxHQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsR0FBQSxFQUFBLElBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLE9BQUEsRUFBQSxJQUFBLEVBQUE7O0FBQUEsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBVztBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFkOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQU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iA8IEsgYW5kIGRwW2ogKyAxXSA+IGRwW2pdXG5cdFx0XHRcdFx0ZHBbaiArIDFdID0gZHBbal1cblx0XHRcdFx0XHR1c2VkW2ogKyAxXSA9IHVzZWRbal1cblx0XHRcdFx0ZHBbal0gKz0gMVxuXHRcdFx0XHR1c2VkW2pdID0ge31cblx0XHRcdHVzZWRbal1bYV0gPSAxXG5cdHByaW50IG1pbiBkcFxuIl19
//# sourceURL=c:\github\2021\009-CodeForces#708\1497E2\coffee\jimm89.coffee

// Generated by CoffeeScript 2.4.1
  // Problem: hittar inte något kommando som kan exekvera
var N, _, f, k, len, nr, nrs, p2, prepare, randint, ref,
  indexOf = [].indexOf;

nrs = function() {
  var i, k, len, ref, results;
  ref = readline().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

nr = function() {
  return nrs()[0];
};

function range(start, stop, step) {
  if (stop == null) {
    stop = start || 0
    start = 0
  }
  if (!step) step = stop < start ? -1 : 1

  var length = Math.max(Math.ceil((stop - start) / step), 0)
  var range = Array(length)

  for (var idx = 0; idx < length; idx++, start += step) range[idx] = start

  return range;
}
;

//##################################################
N = 3162;

p2 = [];

randint = function(min, max) {
  return min + Math.floor(Math.random() * (max - min + 1));
};

prepare = function() {
  var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;
  p = (function() {
    var k, len, ref, results;
    ref = range(N);
    results = [];
    for (k = 0, len = ref.length; k < len; k++) {
      i = ref[k];
      results.push(1);
    }
    return results;
  })();
  ref = range(2, N);
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    if (p[i]) {
      ref1 = range(2 * i, N, i);
      for (l = 0, len1 = ref1.length; l < len1; l++) {
        j = ref1[l];
        p[j] = 0;
      }
    }
  }
  ref2 = range(2, N);
  results = [];
  for (m = 0, len2 = ref2.length; m < len2; m++) {
    c = ref2[m];
    if (p[c] === 1) {
      results.push(c * c);
    }
  }
  return results;
};

f = function(a) {
  var ans, hash, k, kl, l, len, len1, q, r, r0;
  ans = 1;
  kl = {};
  hash = {};
  for (k = 0, len = a.length; k < len; k++) {
    r0 = a[k];
    if (indexOf.call(hash, r0) >= 0) {
      r = hash[r0];
    } else {
      r = r0;
      for (l = 0, len1 = p2.length; l < len1; l++) {
        q = p2[l];
        if (r < q) {
          break;
        }
        while (r % q === 0) {
          r = Math.floor(r / q);
        }
      }
      hash[r0] = r;
    }
    if (r in kl) {
      ans += 1;
      kl = {};
    }
    kl[r] = 1;
  }
  return ans;
};

p2 = prepare();

ref = range(nr());
for (k = 0, len = ref.length; k < len; k++) {
  _ = ref[k];
  _ = nrs();
  print(f(nrs()));
}

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiamF2YXNjcmlwdC5qcyIsInNvdXJjZVJvb3QiOiIuLiIsInNvdXJjZXMiOlsiY29mZmVlXFxqYXZhc2NyaXB0LmNvZmZlZSJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7QUFBQSxJQUFBLENBQUEsRUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLENBQUEsRUFBQSxHQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLE9BQUEsRUFBQSxHQUFBO0VBQUE7O0FBQ0EsR0FBQSxHQUFNLFFBQUEsQ0FBQSxDQUFBO0FBQUcsTUFBQSxDQUFBLEVBQUEsQ0FBQSxFQUFBLEdBQUEsRUFBQSxHQUFBLEVBQUE7QUFBWTtBQUFBO0VBQUEsS0FBQSxxQ0FBQTs7aUJBQVgsUUFBQSxDQUFTLENBQVQ7RUFBVyxDQUFBOztBQUFmOztBQUNOLEVBQUEsR0FBSyxRQUFBLENBQUEsQ0FBQTtTQUFHLEdBQUEsQ0FBQSxDQUFNLENBQUEsQ0FBQTtBQUFUOztBQUVMOzs7Ozs7Ozs7Ozs7Ozs7Q0FKQTs7O0FBc0JB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ha1xyXG5cdFx0XHRcdHdoaWxlIHIgJSBxID09IDBcclxuXHRcdFx0XHRcdHIgLy89IHFcclxuXHRcdFx0aGFzaFtyMF0gPSByXHJcblx0XHRpZiByIG9mIGtsXHJcblx0XHRcdGFucyArPSAxXHJcblx0XHRcdGtsID0ge31cclxuXHRcdGtsW3JdID0gMVxyXG5cdGFuc1xyXG5cclxucDIgPSBwcmVwYXJlKClcclxuZm9yIF8gaW4gcmFuZ2UgbnIoKVxyXG5cdF8gPSBucnMoKVxyXG5cdHByaW50IGYgbnJzKClcclxuIl19
//# sourceURL=c:\github\2021\010\coffee\javascript.coffee

// Generated by CoffeeScript 2.4.1
var N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,
  indexOf = [].indexOf;

print = console.log;

process.stdin.resume();

process.stdin.setEncoding('utf-8');

inputString = '';

currentLine = 0;

process.stdin.on('data', function(inputStdin) {
  return inputString += inputStdin;
});

process.stdin.on('end', function(_) {
  inputString = inputString.trim().split('\n').map(function(string) {
    return string.trim();
  });
  return main();
});

input = function() {
  return inputString[currentLine++];
};

nr = function() {
  return parseInt(input());
};

nrs = function() {
  var i, k, len, ref, results;
  ref = input().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

function range(start, stop, step) {
  if (stop == null) {
    stop = start || 0
    start = 0
  }
  if (!step) step = stop < start ? -1 : 1

  var length = Math.max(Math.ceil((stop - start) / step), 0)
  var range = Array(length)

  for (var idx = 0; idx < length; idx++, start += step) range[idx] = start

  return range;
}
  // range = (start, stop, step) ->
  // 	if stop == undefined
  // 		stop = start || 0
  // 		start = 0
  // 	if step == undefined
  // 		step = if stop < start then -1 else 1
  // 	length = Math.max(Math.ceil((stop - start) / step), 0)
  // 	i for i in [start...start+length] by step
;

//##################################################
N = 3162;

p2 = [];

randint = function(min, max) {
  return min + Math.floor(Math.random() * (max - min + 1));
};

prepare = function() {
  var c, i, j, k, l, len, len1, len2, m, p, ref, ref1, ref2, results;
  p = (function() {
    var k, len, ref, results;
    ref = range(N);
    results = [];
    for (k = 0, len = ref.length; k < len; k++) {
      i = ref[k];
      results.push(1);
    }
    return results;
  })();
  ref = range(2, N);
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    if (p[i]) {
      ref1 = range(2 * i, N, i);
      for (l = 0, len1 = ref1.length; l < len1; l++) {
        j = ref1[l];
        p[j] = 0;
      }
    }
  }
  ref2 = range(2, N);
  results = [];
  for (m = 0, len2 = ref2.length; m < len2; m++) {
    c = ref2[m];
    if (p[c] === 1) {
      results.push(c * c);
    }
  }
  return results;
};

f = function(a) {
  var ans, hash, k, kl, l, len, len1, q, r, r0;
  ans = 1;
  kl = {};
  hash = {};
  for (k = 0, len = a.length; k < len; k++) {
    r0 = a[k];
    if (indexOf.call(hash, r0) >= 0) {
      r = hash[r0];
    } else {
      r = r0;
      for (l = 0, len1 = p2.length; l < len1; l++) {
        q = p2[l];
        if (r < q) {
          break;
        }
        while (r % q === 0) {
          r = Math.floor(r / q);
        }
      }
      hash[r0] = r;
    }
    if (r in kl) {
      ans += 1;
      kl = {};
    }
    kl[r] = 1;
  }
  return ans;
};

main = function() {
  var _, k, len, ref, results;
  p2 = prepare();
  ref = range(nr());
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    _ = ref[k];
    [_, _] = nrs();
    results.push(print(f(nrs())));
  }
  return results;
};

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQS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JdID0gMVxuXHRhbnNcblxubWFpbiA9IC0+XG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIHJhbmdlIG5yKClcblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuIl19
//# sourceURL=c:\github\2021\010\coffee\app.coffee

// Generated by CoffeeScript 2.4.1
var N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,
  indexOf = [].indexOf;

print = console.log;

process.stdin.resume();

process.stdin.setEncoding('utf-8');

inputString = '';

currentLine = 0;

process.stdin.on('data', function(inputStdin) {
  return inputString += inputStdin;
});

process.stdin.on('end', function(_) {
  inputString = inputString.trim().split('\n').map(function(string) {
    return string.trim();
  });
  return main();
});

input = function() {
  return inputString[currentLine++];
};

nr = function() {
  return parseInt(input());
};

nrs = function() {
  var i, k, len, ref, results;
  ref = input().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

// range = (start, stop, step) ->
// 	if stop == undefined
// 		stop = start || 0
// 		start = 0
// 	if step == undefined
// 		step = if stop < start then -1 else 1
// 	length = Math.max(Math.ceil((stop - start) / step), 0)
// 	i for i in [start...start+length] by step

//##################################################
N = 3162;

p2 = [];

randint = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

prepare = function() {
  var c, i, j, k, l, m, p, ref, ref1, ref2, ref3, ref4, results;
  p = (function() {
    var k, ref, results;
    results = [];
    for (i = k = 0, ref = N; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {
      results.push(1);
    }
    return results;
  })();
  for (i = k = 2, ref = N; (2 <= ref ? k < ref : k > ref); i = 2 <= ref ? ++k : --k) {
    if (p[i]) {
      for (j = l = ref1 = 2 * i, ref2 = N, ref3 = i; ref3 !== 0 && (ref3 > 0 ? l < ref2 : l > ref2); j = l += ref3) {
        p[j] = 0;
      }
    }
  }
  results = [];
  for (c = m = 2, ref4 = N; (2 <= ref4 ? m < ref4 : m > ref4); c = 2 <= ref4 ? ++m : --m) {
    if (p[c] === 1) {
      results.push(c * c);
    }
  }
  return results;
};

f = function(a) {
  var ans, hash, k, kl, l, len, len1, q, r, r0;
  ans = 1;
  kl = {};
  hash = {};
  for (k = 0, len = a.length; k < len; k++) {
    r0 = a[k];
    if (indexOf.call(hash, r0) >= 0) {
      r = hash[r0];
    } else {
      r = r0;
      for (l = 0, len1 = p2.length; l < len1; l++) {
        q = p2[l];
        if (r < q) {
          break;
        }
        while (r % q === 0) {
          r = Math.floor(r / q);
        }
      }
      hash[r0] = r;
    }
    if (r in kl) {
      ans += 1;
      kl = {};
    }
    kl[r] = 1;
  }
  return ans;
};

main = function() {
  var _, k, ref, results;
  p2 = prepare();
  results = [];
  for (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {
    [_, _] = nrs();
    results.push(print(f(nrs())));
  }
  return results;
};

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLElBQUEsQ0FBQSxFQUFBLFdBQUEsRUFBQSxDQUFBLEVBQUEsS0FBQSxFQUFBLFdBQUEsRUFBQSxJQUFBLEVBQUEsRUFBQSxFQUFBLEdBQUEsRUFBQSxFQUFBLEVBQUEsT0FBQSxFQUFBLEtBQUEsRUFBQSxPQUFBO0VBQUE7O0FBQUEsS0FBQSxHQUFRLE9BQU8sQ0FBQzs7QUFFaEIsT0FBTyxDQUFDLEtBQUssQ0FBQyxNQUFkLENBQUE7O0FBQ0EsT0FBTyxDQUFDLEtBQUssQ0FBQyxXQUFkLENBQTBCLE9BQTFCOztBQUVBLFdBQUEsR0FBYzs7QUFDZCxXQUFBLEdBQWM7O0FBRWQsT0FBTyxDQUFDLE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XHRlbHNlXG5cdFx0XHRyID0gcjBcblx0XHRcdGZvciBxIGluIHAyXG5cdFx0XHRcdGlmIHIgPCBxXG5cdFx0XHRcdFx0YnJlYWtcblx0XHRcdFx0d2hpbGUgciAlIHEgPT0gMFxuXHRcdFx0XHRcdHIgLy89IHFcblx0XHRcdGhhc2hbcjBdPXJcblx0XHRpZiByIG9mIGtsXG5cdFx0XHRhbnMgKz0gMVxuXHRcdFx0a2wgPSB7fVxuXHRcdGtsW3JdID0gMVxuXHRhbnNcblxubWFpbiA9IC0+XG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIFswLi4ubnIoKV1cblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuIl19
//# sourceURL=c:\github\2021\010\coffee\app.coffee

// Generated by CoffeeScript 2.4.1
  //_ = require 'underscore'

  //range = _.range
var N, currentLine, f, input, inputString, main, nr, nrs, p2, prepare, print, randint,
  indexOf = [].indexOf;

print = console.log;

process.stdin.resume();

process.stdin.setEncoding('utf-8');

inputString = '';

currentLine = 0;

process.stdin.on('data', function(inputStdin) {
  return inputString += inputStdin;
});

process.stdin.on('end', function(_) {
  inputString = inputString.trim().split('\n').map(function(string) {
    return string.trim();
  });
  return main();
});

input = function() {
  return inputString[currentLine++];
};

nr = function() {
  return parseInt(input());
};

nrs = function() {
  var i, k, len, ref, results;
  ref = input().split(' ');
  results = [];
  for (k = 0, len = ref.length; k < len; k++) {
    i = ref[k];
    results.push(parseInt(i));
  }
  return results;
};

//##################################################
N = 3162;

p2 = [];

randint = function(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};

prepare = function() {
  var c, i, j, k, l, m, p, ref, ref1, ref2, ref3, ref4, results;
  p = (function() {
    var k, ref, results;
    results = [];
    for (i = k = 0, ref = N; (0 <= ref ? k < ref : k > ref); i = 0 <= ref ? ++k : --k) {
      results.push(1);
    }
    return results;
  })();
  for (i = k = 2, ref = N; (2 <= ref ? k < ref : k > ref); i = 2 <= ref ? ++k : --k) {
    if (p[i]) {
      for (j = l = ref1 = 2 * i, ref2 = N, ref3 = i; ref3 !== 0 && (ref3 > 0 ? l < ref2 : l > ref2); j = l += ref3) {
        p[j] = 0;
      }
    }
  }
  results = [];
  for (c = m = 2, ref4 = N; (2 <= ref4 ? m < ref4 : m > ref4); c = 2 <= ref4 ? ++m : --m) {
    if (p[c] === 1) {
      results.push(c * c);
    }
  }
  return results;
};

f = function(a) {
  var ans, hash, k, kl, l, len, len1, q, r, r0;
  ans = 1;
  kl = {};
  hash = {};
  for (k = 0, len = a.length; k < len; k++) {
    r0 = a[k];
    if (indexOf.call(hash, r0) >= 0) {
      r = hash[r0];
    } else {
      r = r0;
      for (l = 0, len1 = p2.length; l < len1; l++) {
        q = p2[l];
        if (r < q) {
          break;
        }
        while (r % q === 0) {
          r = Math.floor(r / q);
        }
      }
      hash[r0] = r;
    }
    if (r in kl) {
      ans += 1;
      kl = {};
    }
    kl[r] = 1;
  }
  return ans;
};

main = function() {
  var _, k, ref, results;
  //start = Date.now()
  p2 = prepare();
  results = [];
  for (_ = k = 0, ref = nr(); (0 <= ref ? k < ref : k > ref); _ = 0 <= ref ? ++k : --k) {
    [_, _] = nrs();
    results.push(print(f(nrs())));
  }
  return results;
};

// seed = 1;
// random = () ->
// 	x = Math.sin(seed++) * 10000
// 	x - Math.floor(x)

// print f (Math.floor 1 + 2000000 * random() for i in range 200000)
// #f([9790577 for i in range(200000)])
//print Date.now() - start,'ms'

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXBwLmpzIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlcyI6WyJjb2ZmZWVcXGFwcC5jb2ZmZWUiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7QUFBQSxJQUFBLENBQUEsRUFBQSxXQUFBLEVBQUEsQ0FBQSxFQUFBLEtBQUEsRUFBQSxXQUFBLEVBQUEsSUFBQSxFQUFBLEVB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HRcdFx0ciA9IHIwXG5cdFx0XHRmb3IgcSBpbiBwMlxuXHRcdFx0XHRpZiByIDwgcVxuXHRcdFx0XHRcdGJyZWFrXG5cdFx0XHRcdHdoaWxlIHIgJSBxID09IDBcblx0XHRcdFx0XHRyIC8vPSBxXG5cdFx0XHRoYXNoW3IwXT1yXG5cdFx0aWYgciBvZiBrbFxuXHRcdFx0YW5zICs9IDFcblx0XHRcdGtsID0ge31cblx0XHRrbFtyXSA9IDFcblx0YW5zXG5cbm1haW4gPSAtPlxuXHQjc3RhcnQgPSBEYXRlLm5vdygpXG5cdHAyID0gcHJlcGFyZSgpXG5cdGZvciBfIGluIFswLi4ubnIoKV1cblx0XHRbXyxfXSA9IG5ycygpXG5cdFx0cHJpbnQgZiBucnMoKVxuXG5cdCMgc2VlZCA9IDE7XG5cdCMgcmFuZG9tID0gKCkgLT5cblx0IyBcdHggPSBNYXRoLnNpbihzZWVkKyspICogMTAwMDBcblx0IyBcdHggLSBNYXRoLmZsb29yKHgpXG5cblx0IyBwcmludCBmIChNYXRoLmZsb29yIDEgKyAyMDAwMDAwICogcmFuZG9tKCkgZm9yIGkgaW4gcmFuZ2UgMjAwMDAwKVxuXHQjICNmKFs5NzkwNTc3IGZvciBpIGluIHJhbmdlKDIwMDAwMCldKVxuXHQjcHJpbnQgRGF0ZS5ub3coKSAtIHN0YXJ0LCdtcydcblxuIl19
//# sourceURL=c:\github\2021\010\coffee\app.coffee

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 10e6+1

function main() {
  const value = new Array(maxN + 1).fill(1);
  for (let i = 0; i < maxN + 1; i++) {
    value[i] = i
  }
  //
  for (let i = 2; i < maxN + 1; i++) {
    for (let j = i * i; j < maxN + 1; j += i) {
      while (value[j] % (i * i) === 0) {
        value[j] = value[j] / (i * i)
      }
    }
  }
  // console.log(value)
  var x = parseInt(readline())

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var aa = {}
    for (let i = 0; i < n; i++) {
      a[i] = value[a[i]]
    }

    var array = {}
    var ans = 0
    for (let i = 0; i < n; i++) {
      if (i === 0 || array[a[i]]) {
        ans++
        array = {}
      }
      array[a[i]] = true
    }
    // a = a.sort((a,b)=>a-b)
    // console.log(a)
    console.log(ans)

  });
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 10e6+1

function main() {
  const value = new Array(maxN + 1).fill(1);
  for (let i = 0; i < maxN + 1; i++) {
    value[i] = i
  }
  //
  for (let i = 2; i < maxN + 1; i++) {
    for (let j = i * i; j < maxN + 1; j += i) {
      if (value[j] % (i * i) === 0) {
        value[j] = value[j] / (i * i)
      }
    }
  }
  // console.log(value)
  var x = parseInt(readline())

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var aa = {}
    for (let i = 0; i < n; i++) {
      a[i] = value[a[i]]
    }

    var array = {}
    var ans = 0
    for (let i = 0; i < n; i++) {
      if (i === 0 || array[a[i]]) {
        ans++
        array = {}
      }
      array[a[i]] = true
    }
    // a = a.sort((a,b)=>a-b)
    // console.log(a)
    console.log(ans)

  });
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 10e6

function main() {
  const value = new Array(maxN + 1).fill(1);
  for (let i = 0; i < maxN + 1; i++) {
    value[i] = i
  }
  //
  for (let i = 2; i < maxN + 1; i++) {
    for (let j = i * i; j < maxN + 1; j += i) {
      if (value[j] % (i * i) === 0) {
        value[j] = value[j] / (i * i)
      }
    }
  }
  // console.log(value)
  var x = parseInt(readline())

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var aa = {}
    for (let i = 0; i < n; i++) {
      a[i] = value[a[i]]
    }

    var array = {}
    var ans = 0
    for (let i = 0; i < n; i++) {
      if (i === 0 || array[a[i]]) {
        ans++
        array = {}
      }
      array[a[i]] = true
    }
    // a = a.sort((a,b)=>a-b)
    // console.log(a)
    console.log(ans)

  });
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 30

function main() {
  const value = new Array(maxN + 1).fill(1);
  for (let i = 0; i < maxN + 1; i++) {
    value[i] = i
  }
  //
  for (let i = 2; i < maxN + 1; i++) {
    for (let j = i * i; j < maxN + 1; j += i) {
      if (value[j] % (i * i) === 0) {
        value[j] = value[j] / (i * i)
      }
    }
  }
  // console.log(value)
  var x = parseInt(readline())

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var aa = {}
    for (let i = 0; i < n; i++) {
      a[i] = value[a[i]]
    }

    var array = []
    var ans = 0
    for (let i = 0; i < n; i++) {
      if (i === 0 || array.includes(a[i])) {
        ans++
        array = []
      }
      array.push(a[i])
    }
    // a = a.sort((a,b)=>a-b)
    // console.log(a)
    console.log(ans)

  });
}


var t = readline();
var result = [];
for (var i = 0; i < t; i++) {
	var input = readline().split(" ");
	var diff = input[1] - input[0];
	var count = 0;
	var temp_count = 0;
	var button = [-5,-2,-1,1,2,5];
	if (diff < 0) {
		for (var j = 0; j < button.length && diff != 0; j++) {
			if (diff <= button[j]) {
				temp_count = Math.floor(diff/button[j]);
				count += temp_count;
				diff -= button[j]*temp_count;
			}
		}
	} else if (diff > 0) {
		for (var j = button.length - 1; j >= 0 && diff != 0; j--) {
			if (diff >= button[j]) {
				temp_count = Math.floor(diff/button[j]);
				count += temp_count;
				diff -= button[j]*temp_count;
			}
		}
	}
	result.push(count);
}
for (var i = 0; i < result.length; i++) {
	print(result[i]);
}

var n = parseInt(readline());
var v = [0,1,1,2,2];

for(var i = 0;i<n;++i){
    var arr = readline().split(' ').map(v => parseInt(v));
    var d = Math.abs(arr[0] - arr[1]);
    print(Math.floor(d/5) + v[d%5]);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// thats all what you have to write to get input from stdin, using readLine.

// Main code runs in main();

function main() {
    let testCases = readline();
    while(testCases --){
        var line2 = readline();
        let data = line2.split(' ').map(x => parseInt(x));
        checkSound(data);
    }
}

function checkSound([sound1, sound2]){
    let difference = Math.abs(sound1-sound2);
    let steps = 0;
    steps += parseInt(difference/5);
    if(difference%5 == 1 || difference%5 == 2){
        steps++;
    }
    else if(difference%5 == 3 || difference%5 == 4){
        steps += 2;
    }
    console.log(steps)
}

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = parseInt(arr.shift())

  const c = [0, 1, 1, 2, 2, 1]
  for(let i = 0; i < t; i++) {
    const arrT = arr[i].split(' ').map(a => parseInt(a))
    const a = arrT[0]
    const b = arrT[1]

    if(a == b) console.log(0)
    else {
      let diff = Math.abs(a - b)
      let count = Math.floor(diff / 5)
      diff = diff - count * 5

      count += c[diff]

      console.log(count)
    }
  }
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var a = one[0];
    var b = one[1];
    var diff = Math.abs(a - b);
    var count = Math.floor(diff / 5);
    diff %= 5;
    count += Math.floor(diff / 2);
    diff %= 2;
    count += diff;
    output[i] = count;
  }
  myout(myconv(output, 9));
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let [a, b] = d.split(' ').map(Number);
  let ans = 0;
  let target = Math.abs(a - b);
  const values = [5, 2, 1];
  let idx = 0;

  while (target > 0) {
    ans += Math.floor(target / values[idx]);
    target %= values[idx];
    idx++;
  }

  console.log(ans);
  c++;
});

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let n = nl.num();
  let ans = [];
  for(let i = 0; i < n; i++){
    let [a, b] = nl.nums();
    a = Math.abs(a - b);
    let c = Math.trunc(a/5);
    a %= 5;
    c += Math.trunc(a/2);
    a %= 2;
    c += a;
    ans.push(c);
  }
	console.log(ans.join('\n'));

};

process.stdin.on('end', sol);

'use strict';

var t=parseInt(readline());

while(t--)
{
    var inp = readline().split(' ').map(Number);
    var a=inp[0];
    var b=inp[1];
    var cnt=Math.abs(a-b);

    var res=0;

    while(cnt)
    {
        if(cnt>=5){
            var tmp=parseInt(cnt/5);
            cnt-=(tmp*5);
            res+=tmp;
        }
        else if(cnt>=2){
            var tmp=parseInt(cnt/2);
            cnt-=(tmp*2);
            res+=tmp;
        }
        else {
            res+=cnt;
            cnt=0;
        }
    }

    print(res);
}

var go = function(a, b, steps, floor){
    var add = steps * floor;
    if(a<b) a = a + add;
    else a = a - add;

    if(a<0) return null;

    return countSteps(a,b);

}
var toward = function(a, b, steps){
    var diff = Math.abs(b-a);
    var div = diff/steps;
    var floor = Math.floor(div);
    if(floor>0){
        var h1 = go(a, b, steps, floor);
        var h2 = go(a, b, steps, floor+1);
        if(h2 === null) return floor + h1;
        else return floor + Math.min(h1,1 + h2);
    }
    else{
        h1 = go(a, b, steps, 1);
        if(h1 === null) return 0;
        else return 1 + go(a, b, steps, 1);
    }
}
var countSteps = function(a,b){
    if(a==b) return 0;
    var diff = Math.abs(b-a);
    if(diff > 6){
        return toward(a,b,5);
    }else if(diff === 1 || diff === 2 || diff === 5){
        return 1;
    }else{
        return 2;
    }
}

var n = parseInt(readline());
var i = 0;
while(i<n){
    var numbers = readline().split(" ");
    var a = parseInt(numbers[0]);
    var b = parseInt(numbers[1]);
    write(countSteps(a,b));

    i++;

    if(i!=n) write('\n');
}

var t = readline();
var result = [];
for (var i = 0; i < t; i++) {
	var input = readline().split(" ");
	var diff = input[1] - input[0];
	var count = 0;
	var button = [-5,-2,-1,1,2,5];
	if (diff < 0) {
		for (var j = 0; j < button.length && diff != 0; j++) {
			if (diff < button[j]) {
				count += Math.floor(diff/button[j]);
				diff -= button[j]*count;
			}
		}
	} else if (diff > 0) {
		for (var j = button.length - 1; j >= 0 && diff != 0; j--) {
			if (diff > button[j]) {
				count += Math.floor(diff/button[j]);
				diff -= button[j]*count;
			}
		}
	}
	result.push(count);
}
for (var i = 0; i < result.length; i++) {
	print(result[i]);
}

'use strict';

var t=Number(readline());

while(t--)
{
    var inp = readline().split(' ').map(Number);
    var a=inp[0];
    var b=inp[1];

    var cnt=Math.abs(a-b);

    var res=0;

    while(cnt)
    {
        if(cnt>=5){
            var tmp=cnt/5;
            cnt-=(tmp*5);
            res+=tmp;
        }
        else if(cnt>=2){
            var tmp=cnt/2;
            cnt-=(tmp*2);
            res+=tmp;
        }
        else {
            res+=cnt;
            cnt=0;
        }
    }

    print(res);
}

'use strict';

var t=parseInt(readline());

while(t--)
{
    var inp = readline().split(' ').map(parseInt);
    var a=inp[0];
    var b=inp[1];

    var cnt=parseInt (Math.abs(a-b));

    var res=0;

    while(cnt)
    {
        if(cnt>=5){
            var tmp=parseInt(cnt/5);
            cnt-=(tmp*5);
            res+=tmp;
        }
        else if(cnt>=2){
            var tmp=parseInt(cnt/2);
            cnt-=(tmp*2);
            res+=tmp;
        }
        else {
            res+=cnt;
            cnt=0;
        }
    }

    print(res);
}


//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;

  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		var list = next();
		while(list.indexOf("()") != -1){
			list = list.replace("()","");
		}
		output[i] = list.length / 2;
	}
	myout(myconv(output,9));
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
  data = data.split('\n');
  const testCases = data[0] * 2;
  let i = 1;
  while (i <= testCases) {
    let n = +data[i];
    let s = data[i + 1].trim();
    let count = 0;
    for (let j = 0; j < s.length; j += 1) {
      if (s[j] === '(') count += 1;
      else if (count && s[j] === ')') count -= 1;
    }
    console.log(count);
    i += 2;
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    function solve(sequence) {
        var moves = 0;
        var offset = 0;
        for (var i=0; i<sequence.length; i++) {
            if (sequence[i] === '(') {
                offset++;
            }
            else {
                if (offset >= 1) { offset--; }
                else { moves++; }
            }
        }
        return moves;
    }
    const testCases = parseInt(readline());
    for (var i=0; i<testCases; i++) {
        var length = parseInt(readline());
        var seq = readline();
        console.log(solve(seq));
    }
}

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

const store = {};

function main() {
	let t = readLine() >> 0;

	while (t--) {
		let n = readLine();
		let s = readLine().split('');
		let pos = 0,
			move = 0;

		s.forEach(p => {
			if (p === '(') {
				pos++;
			} else {
				pos--;
				if (pos < 0) {
					pos = 0;
					move++;
				}
			}
		});

		console.log(move);
	}
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
4
2
)(
4
()()
8
())()()(
10
)))((((())

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function main() {
    let n = parseInt(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let length = Number(readline());
    let s = readline().split("");

    const stack = [];
    let count = 0;

    for (let i = 0; i < s.length; i++) {
        const item = s[i];

        if (item === '(') {
            stack.push(item);
        } else {

            const prevItem = stack[stack.length - 1];
            if (item === ')' && prevItem === '(') {
                stack.pop();
            }
        }
    }

    console.log(stack.length);

}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

var lineCount = 0
var testCount = 0
var outputStr = ''

rl.on('line', (input) => {
    if (lineCount == 0) {
        // first line
        testCount = parseInt(input)
    }
    else if(lineCount%2==1){
        //do nothing?
    }
    else if (lineCount >= 2*testCount) {
        outputStr += compute(input) + '\n'
        console.log(outputStr)
        rl.close()
    }
    else {
        // data
        outputStr += compute(input) + '\n'
    }
    lineCount++
});

function compute(str) {
    for(var i=str.length-2;i>=0;i--){
        if(str[i]=='('&&str[i+1]==')'){
            // 删除他俩
            str = `${str.substring(0,i)}${str.substring(i+2, str.length)}`
        }
    }
    return str.length / 2
}

var n = readline();
var llen = [];
var inp = [];
for (var i  = 0; i<n;i++){
    llen[i]=readline();
    inp[i]=readline();
}
function repAll(aa) {
    var b  = true;
    var a = aa.length;
    while (b){
        aa = aa.replace(/\(\)/g,"");
        if (aa.length === a){

            b=false;
        }else{
            a = aa.length;
        }
    }
    return aa;
}
for (var i  = 0; i<n;i++) {
    var tmp = repAll(inp[i]);
    write((tmp.match(/\(/g) || []).length + "\n");

}

var x= parseInt(readline());

while(x--){
  var a=parseInt(readline());
  var seq=readline();

  var open=0,close=0;
  for(var i=0; i<seq.length; i++){
    if(seq[i]==='(')
      open++;
    if(seq[i]===')'){
      if(open>0)
        open--;
      else
        close++;
    }
  }
  print(close);
}

var testCase = Number(readline());
while(testCase--)
{
	readline();
	var str = readline();
	for( var i=1;i<=25;i++)
	{
		str=str.replace('()','');
	}
	print(Math.floor(str.length/2));
}

function solve() {
   var n = Number(read());
   var s = read();
   var min = 0;
   var sum = 0;
   for (var i = 0; i < n; i++) {
      sum += s[i] === '(' ? 1 : -1;
      if (sum < min) {
         min = sum;
      }
   }
   write(0 - min);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', init);
   }
} else {
   init();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let _ = readLine();
    let str = readLine();
    let stack = [];
    for (let i = 0; i < str.length; i++) {
      let char = str[i];
      if (stack[stack.length - 1] === "(" && char === ")") {
        stack.pop();
      } else {
        stack.push(char);
      }
    }
    console.log(stack.length / 2);
  }
}


getInt = () => parseInt(readline());
getFlt = () => parseFloat(readline());
getArrInt = () => readline().split(' ').map(x => parseInt(x));
getArrFlt = () => readline().split(' ').map(x => parseFloat(x));
Int = (x) => Math.floor(x);

nums = getArrInt();
m = nums[0];
n = nums[1];

var t = [];
for(i = 0; i <= m; i++) t[i] = [];

for (var i = 1; i <= m; i++){
	tijs = readline().split(' ').map(x => parseInt(x));
	tijs.forEach((el, j) => {
		t[i][j + 1] = el;
	})
}

dp = new Array( m + 1 ).fill(0);
for(var worker = 1; worker <= n; worker++){
	var getFree = 0;
	for(var pic = 1; pic <= m; pic++){
		getFree = Math.max(getFree, dp[pic]);
		dp[pic] = getFree + t[pic][worker];
		getFree = dp[pic];
	}
}

for(var pic = 1; pic <= m; pic++){
	write (dp[pic] + " ");
}

print(function(m, n){
	var i, j, ans = [], a = [];
	for(i=0; i<m; i++)
		a.push(rn());
	for(i=0; i<m; i++)
		ans[i] = 0;

	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			if(j==0){
				ans[j] = ans[j]+a[j][i];
			}else{
				ans[j] = Math.max( ans[j-1], ans[j] ) + a[j][i];
			}
		}
	}
	return ans.join(' ');
}.apply(0, rn()));
function rn() { return readline().split(' ').map(Number); }

var input = readline().split(' ');
var pictures = parseInt(input[0], 10);
var autors = parseInt(input[1], 10);
var info = [];

for (var i = 0; i < pictures; i++) {
    var input = readline().split(' ');
    info.push(input);
}

for(var i = 1; i < pictures; i++) {
    info[i][0] = parseInt(info[i][0], 10) + parseInt(info[i-1][0], 10);
}

for(var i = 1; i < autors; i++) {
    info[0][i] = parseInt(info[0][i], 10) + parseInt(info[0][i - 1], 10);
}

if (autors > 1) {
    for (var i = 1; i < pictures; i++) {
        for(var j = 1; j < autors; j++) {
            before = parseInt(info[i-1][j], 10);
            actual = parseInt(info[i][j-1], 10);
            info[i][j] = Math.max(before,actual) + parseInt(info[i][j]);
        }
    }
}

var result = [];
for (var i = 0; i < info.length; i++) {
    result.push(info[i].pop());
}
print(result.join(' '));

print(function(m, n) {
    var i, j, ans=[], a=[];
    for(var i=0; i<m; ++i) a.push(rn());
    for(var i=0; i<m; ++i) ans[i]=0;
    for(var i=0; i<n; ++i) {
        for(var j=0; j<m; ++j) {
            if(j==0) ans[j]=ans[j]+a[j][i];
            else ans[j]=Math.max(ans[j-1], ans[j])+a[j][i];
        }
    }
    return ans.join(' ');
}.apply(0, rn()));
function rn() {
    return readline().split(' ').map(Number);
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		numPictures = data[0],
		numArtists = data[1],
		pictures = new Array(numPictures);
	for (var i = 0; i < numPictures; ++i) {
		data = tokenizeIntegers(readline());
		var suffixTime = 0;
		for (var j = 1; j < numArtists; ++j) {
			suffixTime += data[j];
		}
		pictures[i] = { index: i, artistTimes: data, suffixTime: suffixTime };
	}
	if (false) {
		pictures.sort(function (a, b) {
			return b.suffixTime - a.suffixTime;
		});
	}
	var finish = new Array(numPictures);
	finish[0] = new Array(numArtists);
	finish[0][0] = pictures[0].artistTimes[0];
	for (var p = 1; p < numPictures; ++p) {
		finish[p] = new Array(numArtists);
		finish[p][0] = finish[p-1][0] + pictures[p].artistTimes[0];
	}
	for (var a = 1; a < numArtists; ++a) {
		var available = finish[0][a] =
				finish[0][a-1] + pictures[0].artistTimes[a];
		for (var p = 1; p < numPictures; ++p) {
			var start = Math.max(available, finish[p][a-1]);
			available = finish[p][a] =
				start + pictures[p].artistTimes[a];
		}
	}
	var results = new Array(numPictures);
	for (var p = 0; p < numPictures; ++p) {
		results[pictures[p].index] = finish[p][numArtists-1];
	}
	print(results.join(" "));
}

main();

getInt = () => parseInt(readline());
getFlt = () => parseFloat(readline());
getArrInt = () => readline().split(' ').map(x => parseInt(x));
getArrFlt = () => readline().split(' ').map(x => parseFloat(x));
Int = (x) => Math.floor(x);

nums = getArrInt();
m = nums[0];
n = nums[1];

var t = new Array(m + 1);
for(i = 0; i <= m; i++) t[i] = new Array(n + 1);

for (var i = 1; i <= m; i++){
	tijs =
	readline()
	.split(' ')
	.map(x => parseInt(x))
	.forEach((el, j) => {
		t[i][j + 1] = el;
	});
}

dp = new Array( m + 1 ).fill(0);
for(var worker = 1; worker <= n; worker++){
	var getFree = 0;
	for(var pic = 1; pic <= m; pic++){
		getFree = Math.max(getFree, dp[pic]);
		dp[pic] = getFree + t[pic][worker];
		getFree = dp[pic];
	}
}

for(var pic = 1; pic <= m; pic++){
	write (dp[pic] + " ");
}

getInt = () => parseInt(readline());
getFlt = () => parseFloat(readline());
getArrInt = () => readline().split(' ').map(x => parseInt(x));
getArrFlt = () => readline().split(' ').map(x => parseFloat(x));
Int = (x) => Math.floor(x);

nums = getArrInt();
m = nums[0];
n = nums[1];

var t = new Array(m + 1);
for(i = 0; i <= m; i++) t[i] = new Array(n + 1);

for (var i = 1; i <= m; i++){
	tijs = readline().split(' ').map(x => parseInt(x));
	tijs.forEach((el, j) => {
		t[i][j + 1] = el;
	})
}

dp = new Array( m + 1 ).fill(0);
for(var worker = 1; worker <= n; worker++){
	var getFree = 0;
	for(var pic = 1; pic <= m; pic++){
		getFree = Math.max(getFree, dp[pic]);
		dp[pic] = getFree + t[pic][worker];
		getFree = dp[pic];
	}
}

for(var pic = 1; pic <= m; pic++){
	write (dp[pic] + " ");
}

print(function(m, n) {
    var i, j, ans=[], a=[];
    for(var i=0; i<m; ++i) a.push(rn());

    for(var i=0; i<n; ++i) {
        for(var j=0; j<m; ++j) {
            if(j==0) ans[j]=ans[j]+a[j][i];
            else ans[j]=Math.max(ans[j-1], ans[j])+a[j][i];
        }
    }
    return ans.join(' ');
}.apply(0, rn()));
function rn() {
    return readline().split(' ').map(Number);
}

print(function(m, n) {
    var i, j, ans=[], a=[];
    for(var i=0; i<m; ++i) a.push(rn());
    for(var i=0; i<m; ++i) ans[i]=0;
    for(var i=0; i<n; ++i) {
        for(var j=0; j<m; ++j) {
            if(j==0) ans[j]=a[j][i];
            else ans[j]=Math.max(ans[j-1], ans[j])+a[j][i];
        }
    }
    return ans.join(' ');
}.apply(0, rn()));
function rn() {
    return readline().split(' ').map(Number);
}


function min(a, b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}

var line_0 = readline().split(' ');

var n = parseInt(line_0[0]);
var p = parseInt(line_0[1]);
var m = parseInt(line_0[2]);

var answer = 0;

var balance = 0;
var day = 1;
for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ');

    var d = parseInt(line[0]);
    var t = parseInt(line[1]);

    //print(d, day, (d - day) * p);

    balance -= (d - day) * p;
    if (balance < 0) {
        var tmp = -balance;
        var add = min(d - day, Math.ceil(tmp / p));
        answer += add;
        //print("!!", add, "!!", balance, Math.ceil(tmp / p), d - day);
    }
    balance += t;
    day = d;
}
//print(answer);

balance -= (m+1 - day) * p;
if (balance < 0) {
    var tmp = -balance;
    //print("@@", m - day);
    answer += min(m+1 - day, Math.ceil(tmp / p));
}
print(answer);

function parseNumber(x) {
    return parseInt(x);
}

var numbers = readline().split(" ").map(parseNumber);
var N = numbers[0], P = numbers[1], M = numbers[2];
var balance = 0, numOfDays = 0, payments = [];
var lastPaidDay = 0;

for(var i = 0; i < N; i++) {
    var pay = readline().split(" ").map(parseNumber);
	var day = pay[0];
	var value = pay[1];

	var positiveDays = Math.floor(balance / P);
	positiveDays = positiveDays > 0 ?  positiveDays : 0;

	var countedDays = day - lastPaidDay - 1;
	var negDays = countedDays - positiveDays;
	balance -= P*countedDays;

	if(negDays > 0) {
		numOfDays+=negDays;
	}

	balance = balance + value - P;
	if(balance < 0) {
		numOfDays++;
	}

	lastPaidDay = day;
}

var positiveDays = Math.floor(balance / P);
positiveDays = positiveDays > 0 ?  positiveDays : 0;
var countedDays = M - lastPaidDay;
var negDays = countedDays - positiveDays
balance -= P*countedDays;

if(negDays > 0) {
	numOfDays+=negDays;
}

write(numOfDays);

function parseNumber(x) {
    return parseInt(x);
}

var numbers = readline().split(" ").map(parseNumber);
var N = numbers[0], P = numbers[1], M = numbers[2];
var balance = 0, numOfDays = 0, payments = [];
var lastPaidDay = 0;

for(var i = 0; i < N; i++) {
    var pay = readline().split(" ").map(parseNumber);
	var day = pay[0];
	var value = pay[1];

	var positiveDays = Math.floor(balance / P);

	var countedDays = day - lastPaidDay - 1;
	var negDays = countedDays - positiveDays;
	balance -= P*countedDays;

	if(negDays > 0) {
		numOfDays+=negDays;
	}

	balance = balance + value - P;
	if(balance < 0) {
		numOfDays++;
	}

	lastPaidDay = day;
}

var positiveDays = Math.floor(balance / P);
var countedDays = M - lastPaidDay;
var negDays = countedDays - positiveDays
balance -= P*countedDays;

if(negDays > 0) {
	numOfDays+=negDays;
}

write(numOfDays);


process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    B();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,m] = ti(readline().split(' '));
        let cols = new Array(n);
        for(let i = 0; i < n; i++){
            cols[i] = readline().split(' ');
        }

        let rows = new Array(m);
        for(let i = 0; i < m; i++){
            rows[i] = readline().split(' ');
        }

        let map = new Array(10);
        for(let i = 0; i < n; i++){
            for(let j = 0; j < m; j++){
                map[pi(cols[i][j])] = new Array(2);
                map[pi(cols[i][j])][1] = j;
            }
        }

        for(let i = 0; i < m; i++){
            for(let j = 0; j < n; j++){
                map[pi(rows[i][j])][0] = j;
            }
        }

        let res = new Array(n);
        for(let i = 0; i < n; i++){
            res[i] = new Array(m);
        }

        for(let i = 0; i < n; i++){
            for(let j = 0; j < m; j++){
                let r = map[pi(cols[i][j])][0];
                let c = map[pi(cols[i][j])][1];
                res[r][c] = cols[i][j];
            }
        }

        for(let i = 0; i < n; i++){
            console.log(res[i].join(' '));
        }
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [rowLen, colLen] = readLine().split(" ").map(Number);
    const [rowMap, colMap] = [new Map(), new Map()];
    const result = [...Array(rowLen).fill(0)].map((_) => Array(colLen).fill(0));
    for (let i = 0; i < rowLen; i++) {
      readLine()
        .split(" ")
        .map((n, index) => {
          n = parseInt(n);
          colMap.set(n, index);
        });
    }
    for (let i = 0; i < colLen; i++) {
      readLine()
        .split(" ")
        .map((n, index) => {
          n = parseInt(n);
          rowMap.set(n, index);
          const col = colMap.get(n);
          result[index][col] = n;
        });
    }

    for (let i = 0; i < rowLen; i++) {
      console.log(result[i].join(" "));
    }
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = [];
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var M = one[1];
		var list = new Array(N);
		for(var j = 0; j < N; j++){
			list[j] = new Array(M);
		}
		var check = new Array(N);
		var check2 = new Array(M);
		var map = {};
		for(var j = 0; j < N; j++){
			check[j] = nextIntArray();
			for(var k = 0; k < M; k++){
				map[check[j][k]] = k;
			}
		}

		for(var j = 0; j < M; j++){
			tmp = nextIntArray();
			var L = map[tmp[0]];
			for(var k = 0; k < N; k++){
				list[k][L] = tmp[k];
			}
		}
		for(var j = 0; j < N; j++){
			output.push(myconv(list[j], 8));
		}

	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let s="",i=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(i=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{s+=t})),process.stdin.on("end",(e=>{i=s.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return i[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312));o.default.runEachTest((function(){let[t,e]=o.default.nextNumbers(),r=o.default.nextNumbersMatrix(t),n=r.transpose(),s=[...n[0]].sortAsc().join(""),i=o.default.nextNumbersMatrix(e),u=i.deepCopy().map((t=>t.sortAsc().join(""))),l=i[u.findIndex((t=>t==s))],a=n[0].map((t=>l.indexOf(t))),p=Array.numbersMatrix(t,e),f=0;for(let t of a){for(let n=0;n<e;++n)p[t][n]=r[f][n];f++}o.default.puts(p.toString())}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, m] = io.nextNumbers()
//   let a = io.nextNumbersMatrix(n)
//
//   let cols = a.transpose()
//
//   let c = [...cols[0]].sortAsc().join("")
//   let b = io.nextNumbersMatrix(m)
//   let bb = b.deepCopy().map((x) => x.sortAsc().join(""))
//
//   let f = b[bb.findIndex((x) => x == c)]
//
//   let indices = cols[0].map((x) => f.indexOf(x))
//
//   let h = Array.numbersMatrix(n, m)
//   let k = 0
//
//   for (let i of indices) {
//     for (let j = 0; j < m; ++j) {
//       h[i][j] = a[k][j]
//     }
//     k++
//   }
//
//   io.puts(h.toString())
// }
//
// io.runEachTest(main)
// // io.runMain(main)


var n = +readline();
var a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;
var suma = 0, sumb = 0;
while (i < n && j < n){
    if (turna){
        turna = false;
        if (a[i] >= b[j]){
            suma += a[i];
            i++;
        } else if (a[i] < b[j]){
            j++;
        }
    } else {
        turna = true;
        if (b[j] >= a[i]){
            sumb += b[j];
            j++;
        } else if (b[j] < a[i]){
            i++;
        }
    }
}
if (i !== n){
    if (!turna) i++;
    while (i < n){
        suma += a[i];
        i+=2;
    }
} else if (j !== n) {
    if (turna) j++;
    while (j < n){
        sumb += b[j];
        j+= 2;
    }
}
print(suma - sumb);

// Gambling - https://codeforces.com/problemset/problem/1038/C

const main = async () => {
    let listLen = 0;
    const listA = [];
    const listB = [];

    const rl = require("readline").createInterface({
      input: process.stdin,
      output: process.stdout,
    });

    for await (const line of rl) {
      if (!listLen) {
        listLen = Number(line);
      } else {
        if (listA.length < listLen) {
            sortList(line.split(' ')).map((item)=> listA.push(Number(item)));
        } else {
            rl.close();
            sortList(line.split(' ')).map((item)=> listB.push(Number(item)));
        }
      }
    }

    runGame(listLen, listA, listB);
  };

  const sortList = (list) => list.sort((a, b) => a - b)

  const runGame = (listLen, listA, listB) => {

    let scoreA = 0;
    let scoreB = 0;

    for (let i = 0; i <= listLen * 2; i++) {
        // console.log({listA, scoreA, '':'', scoreB, listB})
        if (i % 2 === 0) {
            if (!listB.length || listA[listA.length - 1] > listB[listB.length - 1]) {
                scoreA += listA[listA.length - 1] || 0;
                listA.pop()
            } else {
                listB.pop()
            }
        } else {
            if (!listA.length || listB[listB.length - 1] > listA[listA.length - 1]) {
                scoreB += listB[listB.length - 1] || 0;
                listB.pop()
            } else {
                listA.pop()
            }
        }

    }

    console.log(scoreA - scoreB);
  };

  main();

var n = +readline();
var a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;
var suma = 0, sumb = 0;
while (i < n && j < n){
    if (turna){
        turna = false;
        if (a[i] > b[j]){
            suma += a[i];
            i++;
        } else if (a[i] < b[j]){
            j++;
        } else {
            i++;
            j++;
        }
    } else {
        turna = true;
        if (b[j] > a[i]){
            sumb += b[j];
            j++;
        } else if (b[j] < a[i]){
            i++;
        } else {
            i++;j++;
        }
    }
}
if (i !== n){
    while (i < n){
        suma += a[i];
        i+=2;
    }
} else if (j !== n) {
    while (j < n){
        sumb += b[j];
        j+= 2;
    }
}
print(suma - sumb);

var n = +readline();
var a = readline().split(' ').map(Number).sort((x,y)=>y-x),b = readline().split(' ').map(Number).sort((x,y)=>y-x), turna = true, i = 0,j =0;
var suma = 0, sumb = 0;
while (i < n && j < n){
    if (turna){
        turna = false;
        if (a[i] >= b[j]){
            suma += a[i];
            i++;
        } else if (a[i] < b[j]){
            j++;
        }
    } else {
        turna = true;
        if (b[j] >= a[i]){
            sumb += b[j];
            j++;
        } else if (b[j] < a[i]){
            i++;
        }
    }
}
if (i !== n){
    while (i < n){
        suma += a[i];
        i+=2;
    }
} else if (j !== n) {
    while (j < n){
        sumb += b[j];
        j+= 2;
    }
}
print(suma - sumb);