list4 = [4, 44, 444, 4444, 44444]
list7 = [7, 77, 777, 7777, 77777]
list10 = [10, 100, 1000, 10000, 100000]
index = -1

def equals(x, y):
    for i in range(index, -1, -1):
        mod1 = x % list10[i]
        mod2 = y % list10[i]
        if ((mod1 > list4[i]) and (mod1 <= list7[i])):
            group1 = 2
        else:
            group1 = 1 
        if ((mod2 >= list4[i]) and (mod2 < list7[i])):
            group2 = 1
        else:
            group2 = 2
        if (group1 == group2):
            return False
    return True
    
t = int(input(''))
for i in range(t):
        n = int(input(''))
        result = 0
        index = 0
        for j in range(1, n+1):
             if (j == list4[index + 1]):
                 index += 1
             for k in range(j, n+1):
                 if equals(j, k):
                     result += 1
        print(result, index)    