import math, sequtils, strutils, sugar const m = 10 ^ 9 + 7 k = 5 * 10 ^ 8 let n = parseInt readLine stdin xs = newSeq.collect: for _ in 0 ..< n: let cd = stdin.readLine.split.map parseInt c = cd[0] mod m var d = cd[1] result = 0 while d > k: result += (c + 1) div 2 * k result = result mod m d -= k result += (c + 1) div 2 * d result mod m echo (sum xs) mod m