#include using namespace std; int faq(int l, int r, int fuckl, int fuckr, int fl, int fr) { return max(0, (fr - fl + 1) * 2 - (fl == l) * fuckl - (fr == r) * fuckr); } int main() { int T; scanf("%d", &T); while (T--) { int l1, l2, l3, l4; long long k; scanf("%d%d%d%d%lld", &l1, &l2, &l3, &l4, &k); vector sum(1600001, 0); sum[0]++; for (int i = 1; i <= 400000; i++) { int l = (i + 1) / 2, r = i; int fuckl = (i % 2) ^ 1, fuckr = 1; sum[4 * i] += 4 * faq(l, r, fuckl, fuckr, l, min(r, l1)); sum[3 * i] += 4 * faq(l, r, fuckl, fuckr, max(l, l1 + 1), min(r, l2)); sum[2 * i] += 4 * faq(l, r, fuckl, fuckr, max(l, l2 + 1), min(r, l3)); sum[i] += 4 * faq(l, r, fuckl, fuckr, max(l, l3 + 1), min(r, l4)); } long long res = 0; for (int i = 0; i <= 1600000 && k; i++) { long long cur = min(k, sum[i]); k -= cur; res += cur * i; } printf("%lld\n", res); } return 0; }