{"raw_statement":[{"iden":"statement","content":"After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help.\n\nFormally the parking can be represented as a matrix 109 × 109. There is exactly one car in every cell of the matrix. All cars have their own machine numbers represented as a positive integer. Let's index the columns of the matrix by integers from 1 to 109 from left to right and the rows by integers from 1 to 109 from top to bottom. By coincidence it turned out, that for every cell (_x_, _y_) the number of the car, which stands in this cell, is equal to the minimum positive integer, which can't be found in the cells (_i_, _y_) and (_x_, _j_), 1 ≤ _i_ < _x_, 1 ≤ _j_ < _y_.\n\n<center>![image](https://espresso.codeforces.com/b8c19814ed2984420031e827a5f67c82d4a6bbca.png) The upper left fragment 5 × 5 of the parking</center>Leha wants to ask the watchman _q_ requests, which can help him to find his car. Every request is represented as five integers _x_1, _y_1, _x_2, _y_2, _k_. The watchman have to consider all cells (_x_, _y_) of the matrix, such that _x_1 ≤ _x_ ≤ _x_2 and _y_1 ≤ _y_ ≤ _y_2, and if the number of the car in cell (_x_, _y_) does not exceed _k_, increase the answer to the request by the number of the car in cell (_x_, _y_). For each request Leha asks the watchman to tell him the resulting sum. Due to the fact that the sum can turn out to be quite large, hacker asks to calculate it modulo 109 + 7.\n\nHowever the requests seem to be impracticable for the watchman. Help the watchman to answer all Leha's requests."},{"iden":"input","content":"The first line contains one integer _q_ (1 ≤ _q_ ≤ 104) — the number of Leha's requests.\n\nThe next _q_ lines contain five integers _x_1, _y_1, _x_2, _y_2, _k_ (1 ≤ _x_1 ≤ _x_2 ≤ 109, 1 ≤ _y_1 ≤ _y_2 ≤ 109, 1 ≤ _k_ ≤ 2·109) — parameters of Leha's requests."},{"iden":"output","content":"Print exactly _q_ lines — in the first line print the answer to the first request, in the second — the answer to the second request and so on."},{"iden":"example","content":"Input\n\n4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n\nOutput\n\n1\n13\n93\n0"},{"iden":"note","content":"Let's analyze all the requests. In each case the requested submatrix is highlighted in blue.\n\nIn the first request (_k_ = 1) Leha asks only about the upper left parking cell. In this cell the car's number is 1. Consequentally the answer is 1.\n\n![image](https://espresso.codeforces.com/d0cfce1ecfc6e43d21d60c211dfb7eea89989b30.png)\n\nIn the second request (_k_ = 5) suitable numbers are 4, 1, 2, 3, 2, 1. Consequentally the answer is 4 + 1 + 2 + 3 + 2 + 1 = 13.\n\n![image](https://espresso.codeforces.com/a84f438ac75164f76b71d6a93cc1f943d1605578.png)\n\nIn the third request (_k_ = 10000) Leha asks about the upper left frament 5 × 5 of the parking. Since _k_ is big enough, the answer is equal to 93.\n\n![image](https://espresso.codeforces.com/d4e241bec4723df71cacdd81a4cdba426e434bd5.png)\n\nIn the last request (_k_ = 2) none of the cur's numbers are suitable, so the answer is 0.\n\n![image](https://espresso.codeforces.com/ffe732efa689a47d02e04fe03c2619fcb85c7768.png)"}],"translated_statement":[{"iden":"statement","content":"在餐厅度过一个美好的夜晚后，到了回家的时间。Leha 作为一个真正的绅士，主动提出送 Noora 回家。女孩当然愉快地答应了。但突然出现了一个问题：Leha 在餐厅附近巨大的停车场里找不到自己的车。于是他决定向看守求助。\n\n形式上，停车场可以表示为一个 #cf_span[109 × 109] 的矩阵。矩阵的每个单元格中恰好有一辆车，每辆车都有一个唯一的正整数编号。我们将矩阵的列从左到右用整数 #cf_span[1] 到 #cf_span[109] 编号，行从上到下用整数 #cf_span[1] 到 #cf_span[109] 编号。巧合的是，对于每个单元格 #cf_span[(x, y)]，其中车辆的编号等于最小的正整数，该整数在单元格 #cf_span[(i, y)] 和 #cf_span[(x, j)] 中均未出现，其中 #cf_span[1 ≤ i < x, 1 ≤ j < y]。\n\nLeha 想向看守提出 #cf_span[q] 个请求来帮助他找到自己的车。每个请求由五个整数 #cf_span[x1, y1, x2, y2, k] 表示。看守需要考虑所有满足 #cf_span[x1 ≤ x ≤ x2] 且 #cf_span[y1 ≤ y ≤ y2] 的单元格 #cf_span[(x, y)]，如果单元格 #cf_span[(x, y)] 中车辆的编号不超过 #cf_span[k]，则将该车辆编号加到该请求的答案中。对于每个请求，Leha 要求看守告诉他最终的总和。由于总和可能非常大，Leha 要求对 #cf_span[109 + 7] 取模后输出。\n\n然而，这些请求对看守来说过于复杂。请帮助看守回答 Leha 的所有请求。\n\n第一行包含一个整数 #cf_span[q] #cf_span[(1 ≤ q ≤ 10^4)] —— Leha 的请求数量。\n\n接下来的 #cf_span[q] 行每行包含五个整数 #cf_span[x1, y1, x2, y2, k] #cf_span[(1 ≤ x1 ≤ x2 ≤ 10^9, 1 ≤ y1 ≤ y2 ≤ 10^9, 1 ≤ k ≤ 2·10^9)] —— Leha 请求的参数。\n\n请输出恰好 #cf_span[q] 行 —— 第一行输出第一个请求的答案，第二行输出第二个请求的答案，依此类推。\n\n让我们分析所有请求。在每种情况下，所请求的子矩阵均以蓝色标出。\n\n在第一个请求中 (#cf_span[k = 1])，Leha 只询问左上角的停车场单元格。该单元格中的车辆编号为 #cf_span[1]。因此答案为 #cf_span[1]。\n\n\n\n在第二个请求中 (#cf_span[k = 5])，符合条件的编号为 #cf_span[4, 1, 2, 3, 2, 1]。因此答案为 #cf_span[4 + 1 + 2 + 3 + 2 + 1 = 13]。\n\n\n\n在第三个请求中 (#cf_span[k = 10000])，Leha 询问停车场左上角 #cf_span[5 × 5] 的区域。由于 #cf_span[k] 足够大，答案等于 #cf_span[93]。\n\n\n\n在最后一个请求中 (#cf_span[k = 2])，没有车辆编号符合条件，因此答案为 #cf_span[0]。\n\n\n\n"},{"iden":"input","content":"第一行包含一个整数 #cf_span[q] #cf_span[(1 ≤ q ≤ 10^4)] —— Leha 的请求数量。接下来的 #cf_span[q] 行每行包含五个整数 #cf_span[x1, y1, x2, y2, k] #cf_span[(1 ≤ x1 ≤ x2 ≤ 10^9, 1 ≤ y1 ≤ y2 ≤ 10^9, 1 ≤ k ≤ 2·10^9)] —— Leha 请求的参数。"},{"iden":"output","content":"请输出恰好 #cf_span[q] 行 —— 第一行输出第一个请求的答案，第二行输出第二个请求的答案，依此类推。"},{"iden":"note","content":"让我们分析所有请求。在每种情况下，所请求的子矩阵均以蓝色标出。在第一个请求中 (#cf_span[k = 1])，Leha 只询问左上角的停车场单元格。该单元格中的车辆编号为 #cf_span[1]。因此答案为 #cf_span[1]。在第二个请求中 (#cf_span[k = 5])，符合条件的编号为 #cf_span[4, 1, 2, 3, 2, 1]。因此答案为 #cf_span[4 + 1 + 2 + 3 + 2 + 1 = 13]。在第三个请求中 (#cf_span[k = 10000])，Leha 询问停车场左上角 #cf_span[5 × 5] 的区域。由于 #cf_span[k] 足够大，答案等于 #cf_span[93]。在最后一个请求中 (#cf_span[k = 2])，没有车辆编号符合条件，因此答案为 #cf_span[0]。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ A(x, y) $ denote the car number in cell $ (x, y) $, defined as:  \n$$\nA(x, y) = \\min \\left( \\mathbb{Z}^+ \\setminus \\left( \\{ A(i, y) \\mid 1 \\leq i < x \\} \\cup \\{ A(x, j) \\mid 1 \\leq j < y \\} \\right) \\right)\n$$\n\n**Constraints**  \n1. $ 1 \\leq q \\leq 10^4 $  \n2. For each request: $ 1 \\leq x_1 \\leq x_2 \\leq 10^9 $, $ 1 \\leq y_1 \\leq y_2 \\leq 10^9 $, $ 1 \\leq k \\leq 2 \\cdot 10^9 $  \n\n**Objective**  \nFor each request $ (x_1, y_1, x_2, y_2, k) $, compute:  \n$$\nS = \\left( \\sum_{\\substack{x = x_1 \\\\ y = y_1}}^{x_2, y_2} A(x, y) \\cdot \\mathbf{1}_{A(x, y) \\leq k} \\right) \\mod (10^9 + 7)\n$$","simple_statement":null,"has_page_source":false}