#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
std::pair<long long, long long> req(long long x, long long y, long long k) {
  if (k < 1) return make_pair(0, 0);
  if (x == 0 || y == 0) return make_pair(0, 0);
  if (x == 1 && y == 1) {
    if (k >= 1)
      return make_pair(1, 1);
    else
      return make_pair(0, 0);
  }
  long long deg = 0;
  long long d2 = 1;
  while (max(x, y) > d2) {
    deg++;
    d2 *= 2;
  }
  long long a = d2 / 2;
  if (x > y) swap(x, y);
  if (x <= a) {
    long long m = min(a, k);
    long long sm = ((m * (m + 1)) / 2) % mod;
    std::pair<long long, long long> res = make_pair(x * m, x * sm);
    std::pair<long long, long long> res2 = req(x, y - a, k - a);
    res2.second += res2.first * a;
    res.first += res2.first;
    res.second = (res.second + res2.second) % mod;
    res.first = res.first % mod;
    return res;
  }
  long long m = min(a, k);
  long long sm = ((m * (m + 1)) / 2) % mod;
  std::pair<long long, long long> res = make_pair(a * m, a * sm);
  long long m2 = min(a, k - a);
  if (m2 < 0) m2 = 0;
  long long sm2 = (a * m2 + (m2 * (m2 + 1)) / 2) % mod;
  res.first += (x + y - 2 * a) * m2;
  res.second += (x + y - 2 * a) * sm2;
  std::pair<long long, long long> res2 = req(x - a, y - a, k);
  res.first += res2.first;
  res.first = res.first % mod;
  res.second = (res.second + res2.second) % mod;
  return res;
}
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int x1, y1, x2, y2, k;
    scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &k);
    printf("%lld\n", (req(x2, y2, k).second - req(x1 - 1, y2, k).second -
                      req(x2, y1 - 1, k).second +
                      req(x1 - 1, y1 - 1, k).second + 10 * mod) %
                         mod);
  }
}
