3
1 3
1 4
8 10 10
10 15
1 100
2 100
100 100
15 15
99 99
50 51
2 3
3 4
4 5
2
4
68
 932
424100
424100
9026
377
6049
11074
2
3
5

'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
MOD = 10**9+7
f1, f2 = 0, 1
ss = [0, 0, 1]
for i in range(2, 15004):
    f1, f2 = f2, ((f1 + f2) % 10000)
    ss.append((ss[-1] + f2))

def s(n): return ss[n]

N = input()
for i in xrange(N):
    l, r = map(int, raw_input().split(" "))
    cl, cr = (l-1) / 15000, r / 15000
    result = (cr - cl) * s(15000)
    result += s((r) % 15000)
    result -= s((l-1) % 15000)
    print result%MOD