n = int(input()) total = 0 x = 10**9 + 7 for i in range(n): c, m = map(int, input().split()) if c <= 2: total += m%x elif c % 2 == 0: total += (c - 2) * m % x else: total += (c - 1) * m % x print(total)