import sys import io, os #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from math import gcd N=int(input()) M=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) ANS=0 mod=10**9+7 for a in A: for b in B: ANS=(ANS+(a-1)*(b+1)+gcd(a,b)+1)%mod print(ANS%mod)