//Zang Vũ
#include <iostream>
#include <vector>
#include <math.h>
#include <bitset>
#include <cctype>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define v vector
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define up upper_bound
#define low lower_bound
#define bin binary_search
#define f(array) (array).begin(), (array).end()
#define b(array) (array).rbegin(), (array).rend()
inline ll count(ll left, ll right, ll target) {
ll start = left / target, end = right / target;
if (left % target != 0) start++;
return end - start + 1;
}
int main() {
cin.tie(nullptr), cout.tie(nullptr)
-> ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen ("main.inp", "r", stdin);
freopen ("main.out", "w", stdout);
#endif
int queries;
cin >> queries;
while (queries--) {
ll left, right;
cin >> left >> right;
ll result = count(left, right, 4) + count(left, right, 7) + count(left, right, 11)
- count(left, right, 28) - count(left, right, 44) - count(left, right, 77)
+ count(left, right, 308);
cout << result << endl;
}
}
Ly9aYW5nIFbFqQojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXRoLmg+CiNpbmNsdWRlIDxiaXRzZXQ+CiNpbmNsdWRlIDxjY3R5cGU+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx1bm9yZGVyZWRfbWFwPgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KCiNwcmFnbWEgR0NDIG9wdGltaXplKCJPMyx1bnJvbGwtbG9vcHMiKQojcHJhZ21hIEdDQyB0YXJnZXQoImF2eDIsYm1pLGJtaTIsbHpjbnQscG9wY250IikKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIHYgdmVjdG9yCiNkZWZpbmUgdW1hcCB1bm9yZGVyZWRfbWFwCiNkZWZpbmUgdXNldCB1bm9yZGVyZWRfc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dW50KGxlZnQsIHJpZ2h0LCA0NCkgLSBjb3VudChsZWZ0LCByaWdodCwgNzcpCiAgICAgICAgICAgICAgICAgICsgY291bnQobGVmdCwgcmlnaHQsIDMwOCk7CiAgICAgICAgY291dCA8PCByZXN1bHQgPDwgZW5kbDsKICAgIH0KfQo=