q=int(input()) for _ in range(q): a,b=map(int, input().split()) sum=0 for i in range(1,b+1): sum+=i print(sum%17)