无脑打表就行,,,
#include <bits/stdc++.h>
using namespace std;
#define ls st<<1
#define rs st<<1|1
#define LL long long
const int MAXN= (int) 1e6+10;
LL arr[MAXN];
bool check(LL x) {
if(x%7 == 0)
return false;
while (x) {
if(x%10 == 7)
return false;
x /= 10;
}
return true;
}
void init() {
LL sum = 0;
for (LL i = 0; i < MAXN; ++i) {
arr[i] = 0;
}
for (LL i = 1; i < MAXN; ++i) {
if(!check(i)) {
arr[i] = sum;
continue;
}
sum += i*i;
arr[i] = sum;
}
}
int main() {
ios::sync_with_stdio(false);
int T;
init();
cin >> T;
while (T--) {
LL x;
cin >> x;
cout << arr[x] << endl;
}
return 0;
}