#include #include #include using namespace std; int tn, n, k, ai; int main (int argc, char * const argv[]) { ios_base::sync_with_stdio(false); cin >> tn; assert(1 <= tn && tn <= 10); while (tn--) { long long ret = 0; cin >> n >> k; assert(1 <= n && n <= 100000); assert(1 <= k && k <= 1000000000); for(int i = 0; i < n; i++) { cin >> ai; assert(1 <= ai && ai <= 1000000000); if (ai < k) ret += k - ai % k; else ret += min(ai % k, k - ai % k); } cout << ret << endl; } return 0; } /* 10 8 2 9 10 8 2 9 8 6 7 10 2 -> 8 : +6 9 -> 8 : +1 10 -> 8 : +2 8 -> 8 : +0 2 -> 8 : +6 9 -> 8 : +1 8 -> 8 : +0 6 -> 8 : +2 7 -> 8 : +1 10 -> 8 : +2 6+1+2+0+6+1+0+2+1+2 */