#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repi(i, a, b) for(int i=(a); i>(b); i--)
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define gcd __gcd
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)); (v).erase(unique(all(v)), (v).end());
#define pii pair<int, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0l)
#define EPS 1e-6
#define mod 1000000007
#define MOD 1000000007
#define N 100005
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using maxpq = priority_queue<T>;
//All indexing is 0-based
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
//methods: find_by_order(k); & order_of_key(k);
//To make it an ordered_multiset, use pairs of (value, time_of_insertion)
//to distinguish values which are similar.
template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
//ordered_map<int, int> my_map;
//Returns no. of values x for which ceil(n / x) == y (y must be > 1).
inline ll CC(ll n, ll y) { return iceil(n, y-1) - iceil(n, y); }
//Returns no. of values x for which floor(n / x) == y
inline ll FF(ll n, ll y) { return n / y - n / (y+1); }
//a and b are assumed to be taken modulo p
inline int add(int a, int b, int p = mod){ int c = a + b; if(c >= p) c -= p; return c;}
inline int sub(int a, int b, int p = mod){ int c = a - b; if(c < 0) c += p; return c;}
inline int mul(int a, int b, int p = mod){ return (a * 1ll * b) % p;}
#define int ll
//#define trace(...) 42
//Links:
//Linear sieve and Multiplicative functions: https://c...content-available-to-author-only...s.com/blog/entry/54090
//Mobius Inversion: https://c...content-available-to-author-only...s.com/blog/entry/53925
/* Logic used: Every composite no. can be uniquely represented as
q = i * p; where p is the smallest prime factor and i >= p.
We just need to ensure that every composite no. gets marked exactly once
and we do that when we reach i by considering all primes p <= i
and marking the corresponding nos. (i * p) as composites.
*/
int M[N], cnt[N];
bool isPrime[N];
vector<int> primes;
//Computes the list of all prime numbers <= n and stores in prime.
//Also computes the value of the multiplicative function, func(i) for all i from 1 to n
//and stores in f[i].
void sieve(int n) {
fill(isPrime, isPrime+n+1, 1);
primes.clear();
M[1] = 1;
for(int i = 2; i <= n; i++) {
if(isPrime[i]) {
primes.push_back(i);
M[i] = -1; cnt[i] = 1;
}
for(int p : primes) {
if(i * 1ll * p > n) break;
isPrime[i*p] = 0;
if(i % p == 0) {
M[i*p] = 0; //Since p^2 divides i
cnt[i*p] = cnt[i] + 1;
break;
//if p divides i then for all primes q > p,
//the spf of i*q would be p and not q.
}
else {
M[i*p] = M[i] * M[p];
cnt[i*p] = 1;
}
}
}
}
void prep() {
sieve(N-5);
}
int solve(int b, int d, int k) {
int m = min(b/k, d/k);
int ans = 0;
for(int l = 1; l <= m; l++) {
ans += M[l] * (b/k/l) * (d/k/l);
}
return ans;
}
int32_t main()
{
#ifdef CP
freopen("/home/tarun/Desktop/input.txt", "r", stdin);
// freopen("/home/tarun/Desktop/output.txt", "w", stdout);
#endif
sync;
clock_t clk = clock();
//cerr << "I will return...\n";
prep();
int oo = 1;
tests(t) {
cout << "Case " << oo++ << ": ";
int a, b, c, d, k; cin >> a >> b >> c >> d >> k;
int m = min(b, d);
if(k == 0 || m < k) {
cout << 0 << '\n'; continue;
}
int X = solve(b, d, k);
int Y = solve(m, m, k);
int ans = X - (Y-1)/2;
//trace(X, Y);
cout << ans << '\n';
}
//cerr << "...don't you ever hang your head.\n";
//cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << '\n';
}
//Compile using:
//g++ -o filename.exe --std=c++11 filename.cpp
//Use -D CP for defining a macro CP in the local environment
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+CiNpbmNsdWRlPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CiNkZWZpbmUgcmVwKGksIGEsIGIpIGZvcihpbnQgaT0oYSk7IGk8KGIpOyBpKyspCiNkZWZpbmUgcmVwaShpLCBhLCBiKSBmb3IoaW50IGk9KGEpOyBpPihiKTsgaS0tKQojZGVmaW5lIGRiKHgpIChjZXJyIDw8ICN4IDw8ICI6ICIgPDwgKHgpIDw8ICdcbicpCiNkZWZpbmUgc3luYyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKSwgY2luLnRpZShOVUxMKQojZGVmaW5lIHRlc3RzKHQpIGludCB0OyBjaW4gPj4gdDsgd2hpbGUodC0tKQojZGVmaW5lIGljZWlsKG4sIHgpICgoKG4pICsgKHgpIC0gMSkgLyAoeCkpCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZ2NkIF9fZ2NkCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgcGYgcHVzaF9mcm9udAojZGVmaW5lIHBvYiBwb3BfYmFjawojZGVmaW5lIHBvZiBwb3BfZnJvbnQKI2RlZmluZSBzeiBzaXplKCkKI2RlZmluZSBhbGwod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QgcCA6IHByaW1lcykgewogICAgICAgICAgICBpZihpICogMWxsICogcCA+IG4pIGJyZWFrOwogICAgICAgICAgICBpc1ByaW1lW2kqcF0gPSAwOwogICAgICAgICAgICBpZihpICUgcCA9PSAwKSB7CiAgICAgICAgICAgICAgICBNW2kqcF0gPSAwOyAvL1NpbmNlIHBeMiBkaXZpZGVzIGkKICAgICAgICAgICAgICAgIGNudFtpKnBdID0gY250W2ldICsgMTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgLy9pZiBwIGRpdmlkZXMgaSB0aGVuIGZvciBhbGwgcHJpbWVzIHEgPiBwLAogICAgICAgICAgICAgICAgLy90aGUgc3BmIG9mIGkqcSB3b3VsZCBiZSBwIGFuZCBub3QgcS4KICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIE1baSpwXSA9IE1baV0gKiBNW3BdOwogICAgICAgICAgICAgICAgY250W2kqcF0gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIHByZXAoKSB7CiAgICBzaWV2ZShOLTUpOwp9CgppbnQgc29sdmUoaW50IGIsIGludCBkLCBpbnQgaykgewogICAgaW50IG0gPSBtaW4oYi9rLCBkL2spOwogICAgaW50IGFucyA9IDA7CgogICAgZm9yKGludCBsID0gMTsgbCA8PSBtOyBsKyspIHsKICAgICAgICBhbnMgKz0gTVtsXSAqIChiL2svbCkgKiAoZC9rL2wpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKaW50MzJfdCBtYWluKCkKeyAgIAogICAgI2lmZGVmIENQCiAgICAgICAgZnJlb3BlbigiL2hvbWUvdGFydW4vRGVza3RvcC9pbnB1dC50eHQiLCAiciIsIHN0ZGluKTsKICAgIC8vICBmcmVvcGVuKCIvaG9tZS90YXJ1bi9EZXNrdG9wL291dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYKICAgIHN5bmM7CiAgICBjbG9ja190IG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