#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>
#include<fstream>
using namespace std;
int main()
{
ifstream cin("isco.in");
int t;
cin >> t;
while (t--)
{
int x, y, p, z;
cin >> x >> y >> p >> z;
cout << (x*y - z)*p << endl;;
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxtYXA+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8cXVldWU+CiNpbmNsdWRlPGZzdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKaW50IG1haW4oKQp7CglpZnN0cmVhbSBjaW4oImlzY28uaW4iKTsKCWludCB0OwoJY2luID4+IHQ7Cgl3aGlsZSAodC0tKQoJewoJCWludCB4LCB5LCBwLCB6OwoJCWNpbiA+PiB4ID4+IHkgPj4gcCA+PiB6OwoJCWNvdXQgPDwgKHgqeSAtIHopKnAgPDwgZW5kbDs7Cgl9CiAKCXJldHVybiAwOwp9