#include <iostream>
#include <fstream>
using namespace std;
bool panta (double x, double y, double dx, double dy) {
//cout << y / x << " " << dy / dx << " ";
if ((y / x) > (dy / dx)) {
//cout << 1 << "\n";
return 1;
}
//cout << 0 << "\n";
return 0;
}
long long int solutie (int ord, double x, double y, double dx, double dy, long long zona) {
if (ord == 0) {
return zona;
}
if (x >= 0) {
if (y >= 0) { // NE
if (panta (x, y, dx / 2, dy / 2) == 1) { // zona I
return solutie (ord - 1, x, y - (dy / 2), dx / 2, dy / 2, (1LL * 4 * zona) - 3);
} else { // zona IV
return solutie (ord - 1, x - (dx / 2), y, dx / 2, dy / 2, (1LL * 4 * zona));
}
} else { // SE
if (panta (x, y, dx / 2, -dy / 2) == 1) { // zona IV
return solutie (ord - 1, x - (dx / 2), y, dx / 2, dy / 2, (1LL * 4 * zona));
} else { // zona III
return solutie (ord - 1, x, y + (dy / 2), dx / 2, dy / 2, (1LL * 4 * zona) - 1);
}
}
} else {
if (y >= 0) { // NV
if (panta (x, y, -dx / 2, dy / 2) == 0) { // zona I
return solutie (ord - 1, x, y - (dy / 2), dx / 2, dy / 2, (1LL * 4 * zona) - 3);
} else { // zona II
return solutie (ord - 1, x + (dx / 2), y, dx / 2, dy / 2, (1LL * 4 * zona) - 2);
}
} else { // SV
if (panta (x, y, -dx / 2, -dy / 2) == 0) { // zona II
return solutie (ord - 1, x + (dx / 2), y, dx / 2, dy / 2, (1LL * 4 * zona) - 2);
} else { // zona III
return solutie (ord - 1, x, y + (dy / 2), dx / 2, dy / 2, (1LL * 4 * zona) - 1);
}
}
}
}
int main() {
ifstream file_in ("romb2.in");
ofstream file_out ("romb2.out");
int t;
int dx, dy, ord, x, y;
// Citirea datelor
file_in >> t;
// Calcularea solutiei
for (; t > 0; t--) {
file_in >> dx >> dy >> ord >> x >> y;
// Afisarea solutiei
file_out << solutie (ord, x, y, dx, dy, 1LL) << "\n";
}
return 0;
}
/*
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
#define MAX_L 30003
string s;
string sirInit[15002], putere[130];
int main() {
ifstream file_in ("mesaje.in");
ofstream file_out ("mesaje.out");
char sir0[MAX_L];
string sir;
int l, cuv = 0, lvl;
int i;
// Citirea datelor
file_in.getline(sir0, MAX_L);
l = strlen(sir0);
for (i = 0; i < l; i++) {
if (sir0[i] != ' ') {
s.push_back(sir0[i]);
} else {
sirInit[cuv] = s;
s.clear();
putere[cuv++].push_back(0);
}
}
sirInit[cuv] = s;
putere[cuv++].push_back(0);
// Calcularea solutiei
lvl = 1;
while (!file_in.eof()) {
for (i = 0; i < cuv; i++) {
file_in >> sir;
if (sir == sirInit[i]) {
putere[i].push_back(lvl);
}
}
lvl++;
}
// Afisarea solutiei
return 0;
}*/