Enter-View $\left({\mbox{EV}}\right)$ is a linear, street-like country. By linear, we mean all the cities of the country are placed on a single straight line - the $\boldsymbol{x}$-axis. Thus every city's position can be defined by a single coordinate, $x_i$, the distance from the left borderline of the country. You can treat all cities as single points.

Unfortunately, the dictator of telecommunication of EV (Mr. S. Treat Jr.) doesn't know anything about the modern telecom technologies, except for peer-to-peer connections. Even worse, his thoughts on peer-to-peer connections are extremely faulty: he believes that, if $P_i$ people are living in city $\boldsymbol{i}$, there must be at least $P_i$ cables from city $\boldsymbol{i}$ to every other city of EV - this way he can guarantee no congestion will ever occur!

Mr. Treat hires you to find out how much cable they need to implement this telecommunication system, given the coordination of the cities and their respective population. 

Note that The connections between the cities can be shared. Look at the example for the detailed explanation.

Input Format  

A number $\mathbf{T}$ is given in the first line and then comes $\mathbf{T}$ blocks, each representing a scenario.

Each scenario consists of three lines. The first line indicates the number of cities (N). The second line indicates the coordinates of the N cities. The third line contains the population of each of the cities. The cities needn't be in increasing order in the input.

Output Format  

For each scenario of the input, write the length of cable needed in a single line modulo $1,000,000,007$.

Constraints  

$1\leq T\leq20$ 

$1\leq N\leq200,000$ 

$P_i\leq10,000$ 

Border to border length of the country $\leq1,000,000,000$

Sample Input  

2  
3  
1 3 6  
10 20 30  
5  
5 55 555 55555 555555  
3333 333 333 33 35

Sample Output  

280  
463055586

Explanation

For the first test case, having $3$ cities requires $3$ sets of cable connections. Between city $1$ and $2$, which has a population of $10$ and $\textbf{20}$, respectively, Mr. Treat believes at least $10$ cables should come out of city 1 for this connection, and at least 20 cables should come out of city $2$ for this connection. Thus, the connection between city $1$ and city $2$ will require $\textbf{20}$ cables, each crossing a distance of $3-1=2$ km. Applying this absurd logic to connection 2,3 and 1,3, we have

$[1,2]$ => $\textbf{20}$ connections $X$ $2km=40$ km of cable

$[2,3]$ => $30$ connections $X$ $3km=90$ km of cable

$[1,3]$ => $30$ connections $X$ $5km=150$ km of cable

For a total of $280$ , Output is $280$ km of cable

Difficulty: MEDIUM_HARD
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


modulo = 1000000007

class Tree:

	def __init__(self, size):
		self.__size = size
		self.__node = [(0, 0)] * (size << 2)

	@staticmethod
	def __rightChild(node):
		return node << 1 | 1

	@staticmethod
	def __leftChild(node):
		return node << 1

	@staticmethod
	def __parent(node):
		return node >> 1

	def sumInRange(self, leftBound, rightBound):
		if leftBound <= rightBound:
			return self.__recursiveSum(1, 0, self.__size - 1, leftBound, rightBound)
		else:
			return (0, 0)

	def __recursiveSum(self, node, left, right, leftBound, rightBound):
		if leftBound <= left and right <= rightBound:
			return self.__node[node]
		middle = left + right >> 1
		(sumX, sumC) = (0, 0)
		if middle >= leftBound:
			(leftX, leftC) = self.__recursiveSum(Tree.__leftChild(node), left, middle, leftBound, rightBound)
			(sumX, sumC) = (sumX + leftX, sumC + leftC)
		if middle < rightBound:
			(rightX, rightC) = self.__recursiveSum(Tree.__rightChild(node), middle + 1, right, leftBound, rightBound)
			(sumX, sumC) = (sumX + rightX, sumC + rightC)
		return (sumX, sumC)

	def setValueForLeaf(self, tuple, leaf):
		left = 0
		right = self.__size - 1
		node = 1
		while left < right:
			middle = left + right >> 1
			if middle < leaf:
				left = middle + 1
				node = Tree.__rightChild(node)
			else:
				right = middle
				node = Tree.__leftChild(node)
		self.__node[node] = tuple
		__parent = Tree.__parent(node)
		if __parent:
			self.__updateNodeAndParent(__parent)

	def __updateNodeAndParent(self, node):
		(leftX, leftC) = self.__node[Tree.__leftChild(node)]
		(rightX, rightC) = self.__node[Tree.__rightChild(node)]
		self.__node[node] = (leftX + rightX, leftC + rightC)
		__parent = Tree.__parent(node)
		if __parent:
			self.__updateNodeAndParent(__parent)

def direct_connections(x, P, N=-1):
	if N == -1:
		N = len(x)
	data = sorted(zip(x, P))
	cities = sorted(zip(data, range(N)), key=lambda tup: tup[0][1])
	tree = Tree(N)
	sum = 0
	for city in cities:
		xCity = city[0][0]
		pCity = city[0][1]
		index = city[1]
		(leftX, leftC) = tree.sumInRange(0, index - 1)
		(rightX, rightC) = tree.sumInRange(index + 1, N - 1)
		sum += pCity * ((leftC - rightC) * xCity - leftX + rightX)
		sum %= modulo
		tree.setValueForLeaf((xCity, 1), index)
	return sum
T = int(input())
for scenario in range(T):
	N = int(input())
	x = [int(i) for i in input().split()]
	P = [int(i) for i in input().split()]
	cableLength = direct_connections(x, P, N)
	print(cableLength)


class Fenwick_tree:

	def __init__(self, n):
		sz = 1
		while n >= sz:
			sz *= 2
		self.size = sz
		self.data = [0] * sz

	def sum(self, i):
		if i <= 0:
			return 0
		s = 0
		while i >= 0:
			s += self.data[i]
			i = (i & i + 1) - 1
		return s

	def sumrange(self, lo, hi):
		return self.sum(hi - 1) - self.sum(lo - 1)

	def add(self, i, x):
		assert i > 0
		while i < self.size:
			self.data[i] += x
			i |= i + 1

def get_lookup(arr):
	(value_to_idx, idx_to_value) = ({}, {})
	arr.sort()
	idx = 1
	for i in arr:
		if i not in value_to_idx:
			value_to_idx[i] = idx
			idx_to_value[idx] = i
			idx += 1
	return (value_to_idx, idx_to_value)
mod = 10 ** 9 + 7
for case in range(int(input())):
	N = int(input())
	C = list(map(int, input().split()))
	P = list(map(int, input().split()))
	arr = list(sorted(((c, p) for (p, c) in zip(P, C))))
	(cvi, civ) = get_lookup(C)
	(pvi, piv) = get_lookup(P)
	(tpd, tpn) = (Fenwick_tree(N + 1), Fenwick_tree(N + 1))
	(tpdp, tpp) = (Fenwick_tree(N + 1), Fenwick_tree(N + 1))
	ans = 0
	for (c, p) in arr:
		(ci, pi) = (cvi[c], pvi[p])
		num_cit = tpn.sum(pi)
		sum_cit = tpd.sum(pi)
		ans = (ans + (num_cit * c - sum_cit) * p) % mod
		sumprod_cit = tpdp.sumrange(pi + 1, N + 1)
		sum_pop = tpp.sumrange(pi + 1, N + 1)
		ans = (ans + sum_pop * c - sumprod_cit) % mod
		tpn.add(pi, 1)
		tpd.add(pi, c)
		tpdp.add(pi, c * p)
		tpp.add(pi, p)
	print(ans)


class Bit:

	def __init__(self, n):
		sz = 1
		while n >= sz:
			sz *= 2
		self.size = sz
		self.data = [0] * sz

	def sum(self, i):
		assert i > 0
		s = 0
		while i > 0:
			s += self.data[i]
			i -= i & -i
		return s

	def add(self, i, x):
		assert i > 0
		while i < self.size:
			self.data[i] += x
			i += i & -i

class City:

	def __init__(self, pop, pos, index):
		self.pop = pop
		self.pos = pos
		self.index = index

def calculate_length(N, city_pos, city_pop):
	cities = []
	for (n, (pos, pop)) in enumerate(zip(city_pos, city_pop)):
		cities.append(City(pop, pos, 0))
	cities = sorted(cities, key=lambda x: x.pos)
	for (n, city) in enumerate(cities):
		city.index = n + 1
	cities = sorted(cities, key=lambda x: x.pop)
	pos_tree = Bit(N)
	num_tree = Bit(N)
	d = 0
	for city in cities:
		N_left = num_tree.sum(city.index)
		N_right = num_tree.sum(N) - N_left
		x_sum_left = pos_tree.sum(city.index)
		x_sum_right = pos_tree.sum(N) - x_sum_left
		d += city.pop * ((N_left - N_right) * city.pos - x_sum_left + x_sum_right)
		num_tree.add(city.index, 1)
		pos_tree.add(city.index, city.pos)
	return d
numberOfRuns = int(input())
runDetails = []
for j in range(numberOfRuns):
	numOfCities = input()
	cityPos = input()
	cityPop = input()
	runDetails.append((int(numOfCities), [int(i) for i in cityPos.split()], [int(i) for i in cityPop.split()]))
for (n, pos, pop) in runDetails:
	print(calculate_length(n, pos, pop) % 1000000007)


import sys

class BinaryIndexTree:

	def __init__(self, data):
		self.tree = self.bit_create_empty_tree(len(data) + 1)
		for (i, d) in enumerate(data):
			self.bit_update(i + 1, d)

	@staticmethod
	def bit_get_parent(index):
		return index - (index & -index)

	@staticmethod
	def bit_get_next(index):
		return index + (index & -index)

	@staticmethod
	def bit_create_empty_tree(length):
		return [0] * length

	def bit_update(self, index, difference):
		curr_index = index
		while curr_index < len(self.tree):
			self.tree[curr_index] += difference
			curr_index = self.bit_get_next(curr_index)

	def bit_sum_until_index(self, index):
		curr_index = index
		s = 0
		while curr_index > 0:
			s += self.tree[curr_index]
			curr_index = self.bit_get_parent(curr_index)
		return s

	def bit_sum_from_a_to_b(self, a, b):
		if a > b:
			return 0
		return self.bit_sum_until_index(b) - self.bit_sum_until_index(a)
READ_FROM_FILE = False
DEBUG = False
if READ_FROM_FILE:
	f = open('input.txt')
	inp = f.readline
else:
	inp = input
t = int(inp().strip())
for _ in range(t):
	n = int(inp().strip())
	data_by_distance = sorted(zip(map(int, inp().strip().split()), map(int, inp().strip().split())), key=lambda x: x[0])
	data_by_population = sorted(data_by_distance, reverse=True, key=lambda x: x[1])
	coords = [x[0] for x in data_by_distance]
	populations = [x[1] for x in data_by_population]
	bit_count = BinaryIndexTree([1] * n)
	bit_coords = BinaryIndexTree(coords)
	population_to_index_in_coords = {}
	for (i, city) in enumerate(data_by_distance):
		if city[1] in population_to_index_in_coords:
			population_to_index_in_coords[city[1]].append(i)
		else:
			population_to_index_in_coords[city[1]] = [i]
	cable_length = 0
	for population in populations:
		index_in_coords = population_to_index_in_coords[population].pop()
		index_in_tree = index_in_coords + 1
		coord = coords[index_in_coords]
		count_left = bit_count.bit_sum_until_index(index_in_tree - 1)
		count_right = bit_count.bit_sum_from_a_to_b(index_in_tree, n)
		sum_of_coords_left = bit_coords.bit_sum_until_index(index_in_tree - 1)
		sum_of_coords_right = bit_coords.bit_sum_from_a_to_b(index_in_tree, n)
		cable_length += (count_left * coord - sum_of_coords_left) * population + (sum_of_coords_right - count_right * coord) * population
		bit_count.bit_update(index_in_tree, -1)
		bit_coords.bit_update(index_in_tree, -coord)
	cable_length %= 1000000007
	print(cable_length)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


__author__ = 'Ward'
import sys
import collections

class LazyFT:

	def __init__(self, N):
		self.maxValue = N + 1
		self.data = collections.defaultdict(lambda : 0)

	def add(self, i, a):
		i += 1
		while i <= self.maxValue:
			self.data[i] += a
			i += i & -i

	def read(self, i):
		i += 1
		Ans = 0
		while i > 0:
			Ans += self.data[i]
			i -= i & -i
		return Ans

	def query(self, left, right):
		return self.read(right) - self.read(left - 1)

	def update(self, i, a):
		prev = self.query(i, i)
		self.add(i, a - prev)

	def addModP(self, i, a):
		prev = self.query(i, i)
		diff = (prev + a) % prime - prev
		self.add(i, diff)
T = int(sys.stdin.readline())
prime = 1000000007
for t in range(0, T):
	N = int(sys.stdin.readline())
	CP = list(zip(map(int, sys.stdin.readline().split()), map(int, sys.stdin.readline().split())))
	CP.sort(key=lambda x: x[1])
	aTree = LazyFT(1000000000)
	bTree = LazyFT(1000000000)
	Ans = 0
	for city in CP:
		a = aTree.read(city[0])
		b = bTree.read(city[0])
		Ans += (a + b * city[0]) * city[1]
		Ans %= prime
		aTree.addModP(0, city[0])
		aTree.addModP(city[0], -2 * city[0])
		bTree.add(0, -1)
		bTree.add(city[0], 2)
	print(Ans)


M = 300000
mod = 1000000007

def query(q, ind):
	m = p = 0
	while ind:
		m += q[ind][0]
		p += q[ind][1]
		ind -= ind & -ind
	return (m % mod, p)

def update(q, ind, val):
	while ind < M:
		q[ind][0] = (q[ind][0] + val) % mod
		q[ind][1] += 1
		ind += ind & -ind
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	p = list(map(int, input().split()))
	a = list(zip(c, p))
	a.sort()
	for i in range(n):
		a[i] += (i + 1,)
	a.sort(key=lambda x: x[1])
	f = [[0, 0] for _ in range(M)]
	c = d = t = 0
	for (x, y, z) in a:
		(m, p) = query(f, z)
		t = (t + y * ((2 * p - c) * x + d - 2 * m)) % mod
		c += 1
		d += x
		update(f, z, x)
	print(t)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


MOD = 10 ** 9 + 7

class BinaryIndexedTree:

	def __init__(self, maxIndex):
		self.tree = [0] * (maxIndex + 1)

	def add(self, index, value):
		assert index > 0
		while index < len(self.tree):
			self.tree[index] += value
			index += index & -index

	def getSumUpTo(self, index):
		s = 0
		while index > 0:
			s += self.tree[index]
			index -= index & -index
		return s

def solve(N, X, P):
	index = {x: i for (i, x) in enumerate(sorted(X), 1)}
	SX = BinaryIndexedTree(N + 1)
	Sx = BinaryIndexedTree(N + 1)
	total = 0
	for (p, x) in sorted(zip(P, X)):
		i = index[x]
		total += p * (SX.getSumUpTo(N + 1) - x * Sx.getSumUpTo(N + 1) - 2 * (SX.getSumUpTo(i) - x * Sx.getSumUpTo(i)))
		Sx.add(i, 1)
		SX.add(i, x)
	return total % MOD
T = int(input())
for _ in range(T):
	N = int(input())
	X = list(map(int, input().split()))
	P = list(map(int, input().split()))
	print(solve(N, X, P))


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


inf = 1000000000
m = 1000000007

class Node:

	def __init__(self, v):
		self.val = v
		self.cnt = 1
		self.scnt = 1
		self.sum = v
		self.left = None
		self.right = None

def add(r, v):
	r.scnt += 1
	r.sum += v
	if v == r.val:
		r.cnt += 1
	elif v < r.val:
		if r.left:
			add(r.left, v)
		else:
			r.left = Node(v)
	elif r.right:
		add(r.right, v)
	else:
		r.right = Node(v)

def query(r, v):
	if not r:
		return (0, 0)
	if v < r.val:
		(cnt, sum) = query(r.left, v)
	else:
		cnt = r.cnt
		sum = r.cnt * r.val
		if r.left:
			cnt += r.left.scnt
			sum += r.left.sum
		if v > r.val:
			(tn, ts) = query(r.right, v)
			cnt += tn
			sum += ts
	return (cnt, sum)
for _ in range(int(input().strip())):
	n = int(input().strip())
	d = list(map(int, input().strip().split()))
	p = list(map(int, input().strip().split()))
	a = sorted(zip(p, d))
	ans = 0
	(cnt, sum) = (1, a[0][1])
	r = Node(a[0][1])
	for i in range(1, n):
		(nl, sl) = query(r, a[i][1])
		(nr, sr) = (cnt - nl, sum - sl)
		ans += a[i][0] * (nl * a[i][1] % m - sl) % m
		ans += a[i][0] * (sr - nr * a[i][1] % m) % m
		ans %= m
		add(r, a[i][1])
		cnt += 1
		sum += a[i][1]
	print(ans)


from heapq import heappush, heappop

def lsd(n):
	return n & -n

class City(object):

	def __init__(self, x, pop):
		self.x = x
		self.pop = pop

	def __repr__(self):
		return '{} (pop{})'.format(self.x, self.pop)

class BITree(object):

	def __init__(self, data):
		if isinstance(data, int):
			self.arr = [0] * (data + 1)
		else:
			self.arr = [0] * (len(data) + 1)
			for (i, value) in enumerate(data):
				self.update(i, value)

	@property
	def total(self):
		return self.sum_upto(len(self.arr) - 2)

	def sum_upto(self, idx_fromzero):
		idx = idx_fromzero + 1
		res = 0
		while lsd(idx) > 0:
			res += self.arr[idx]
			idx -= lsd(idx)
		return res

	def value_at(self, idx_fromzero):
		idx = idx_fromzero + 1
		base = self.arr[idx]
		ancestor = idx - lsd(idx)
		idx -= 1
		while idx != ancestor:
			base -= self.arr[idx]
			idx -= lsd(idx)
		return base

	def update(self, idx_fromzero, value):
		idx = idx_fromzero + 1
		while idx < len(self.arr):
			self.arr[idx] += value
			idx += lsd(idx)

def get_cable_length(cities):
	cities = sorted(cities, key=lambda city: city.x)
	ncities = len(cities)
	ndists = len(cities) - 1
	asc = BITree(ncities)
	left_nz = BITree(ncities)
	desc = BITree(ncities)
	right_nz = BITree(ncities)
	orig_asc = cities[0].x
	orig_desc = cities[ncities - 1].x
	for i in range(0, ncities):
		ldist = abs(cities[i].x - orig_asc)
		rdist = abs(cities[ncities - 1 - i].x - orig_asc)
		asc.update(i, abs(cities[i].x - orig_asc))
		if ldist > 0:
			left_nz.update(i, 1)
		desc.update(i, abs(cities[ncities - 1 - i].x - orig_desc))
		if rdist > 0:
			right_nz.update(ncities - 1 - i, 1)
	queue = []
	maxpop = max((city.pop for city in cities))
	for (idx, city) in enumerate(cities):
		heappush(queue, (maxpop - city.pop, city.pop, idx))

	def dists(sums, nz, idx):
		total = sums.total
		top = sums.sum_upto(idx)
		at = sums.value_at(idx)
		times = nz.sum_upto(ncities - 1 - idx)
		side = at * times
		res = total - top - side
		return (res, at)
	res = 0
	while len(queue) > 0:
		(_, pop, idx) = heappop(queue)
		didx = ndists - idx
		(rd, lat) = dists(asc, right_nz, idx)
		(ld, rat) = dists(desc, left_nz, didx)
		res += (rd + ld) * pop
		asc.update(idx, -lat)
		if idx + 1 < len(cities):
			left_nz.update(idx + 1, -1)
		desc.update(didx, -rat)
		if didx + 1 < len(cities):
			right_nz.update(didx + 1, -1)
	return res

def main():
	nqueries = int(input().strip())
	for _ in range(0, nqueries):
		int(input().strip())
		coords = [int(x) for x in input().strip().split()]
		pops = [int(x) for x in input().strip().split()]
		cities = [City(x, pop) for (x, pop) in zip(coords, pops)]
		length = get_cable_length(cities)
		print(length % 1000000007)
main()


import sys

def height(c):
	return ((c ^ c - 1) + 1) // 2

def fenwik_add(vals, i, add, pop_max):
	while i <= pop_max:
		vals[i - 1] += add
		i += height(i)

def sum_left(r, vals):
	result = 0
	while r > 0:
		result += vals[r - 1]
		r -= height(r)
	return result

def sum(l, r, vals):
	if l > r:
		return 0
	return sum_left(r, vals) - sum_left(l - 1, vals)
crop = 1000000007
max_pop = 10000
t = int(input().strip())
for some in range(t):
	n = int(input().strip())
	coords = [int(x) for x in input().strip().split(' ')]
	pop = [int(x) for x in input().strip().split(' ')]
	cities = list(zip(coords, pop))
	cities.sort(key=lambda a: a[0])
	counts = [0] * max_pop
	sums = [0] * max_pop
	pops = [0] * max_pop
	weight_sums = [0] * max_pop
	result = 0
	for i in reversed(range(n)):
		(x, pop) = cities[i]
		result += sum(pop + 1, max_pop, weight_sums) - sum(pop + 1, max_pop, pops) * x
		result += (sum(1, pop, sums) - sum(1, pop, counts) * x) * pop
		result = result % crop
		fenwik_add(counts, pop, 1, max_pop)
		fenwik_add(sums, pop, x, max_pop)
		fenwik_add(pops, pop, pop, max_pop)
		fenwik_add(weight_sums, pop, x * pop % crop, max_pop)
	print(result)


MOD = 10 ** 9 + 7

def get_sum_BIT(T, i):
	total = 0
	i += 1
	i = min(i, len(T) - 1)
	while i > 0:
		total += T[i]
		i -= i & -i
	return total

def set_BIT(T, i, v):
	i += 1
	while i < len(T):
		T[i] += v
		i += i & -i

def build_BIT(seq):
	n = len(seq)
	T = [0] * (n + 1)
	for (i, s) in enumerate(seq):
		set_BIT(T, i, s)
	return T
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	X = [int(x) for x in input().strip().split(' ')]
	P = [int(p) for p in input().strip().split(' ')]
	(ordering_X, X) = map(list, zip(*sorted([(i, x) for (i, x) in enumerate(X)], key=lambda x: x[1], reverse=False)))
	(ordering_P, P) = map(list, zip(*sorted([(i, p) for (i, p) in enumerate(P)], key=lambda x: x[1], reverse=True)))
	inverse_ordering_X = sorted(range(n), key=lambda i: ordering_X[i], reverse=False)
	inverse_ordering_P = sorted(range(n), key=lambda i: ordering_P[i], reverse=False)
	map_P_X = [inverse_ordering_X[ordering_P[i]] for i in range(n)]
	TX = build_BIT(X)
	TA = build_BIT([1] * n)
	total = 0
	for (ip, p) in enumerate(P):
		ix = map_P_X[ip]
		x = X[ix]
		left = get_sum_BIT(TX, ix - 1)
		left_count = get_sum_BIT(TA, ix - 1)
		right = get_sum_BIT(TX, n) - get_sum_BIT(TX, ix)
		right_count = get_sum_BIT(TA, n) - get_sum_BIT(TA, ix)
		total = (total + p * (left_count * x - left + (right - right_count * x))) % MOD
		set_BIT(TX, ix, -X[ix])
		set_BIT(TA, ix, -1)
	print(total)


import sys
from filecmp import cmp
from os import linesep
from time import time
MOD = 10 ** 9 + 7

class counter(object):
	__slots__ = ['size', 'C']

	def __init__(self, size=None):
		if size is None:
			size = 10 ** 5
		self.size = 1 << size.bit_length()
		self.C = [0] * self.size

	def increment(self, pos, incr):
		C = self.C
		while pos < self.size:
			C[pos] += incr
			pos += pos & -pos

	def find(self, pos):
		acc = 0
		C = self.C
		assert pos < len(C)
		while pos > 0:
			acc += C[pos]
			pos -= pos & -pos
		return acc

	def count(self, bot=None, top=None):
		if top is None:
			top = self.size - 1
		if bot is None:
			return self.find(top)
		else:
			assert bot >= 0
			assert top <= self.size
			return self.find(top) - self.find(bot - 1)

def process(N, locs, pops):
	cities = sorted(zip(locs, pops))
	size = max(locs) + 1
	count_cities = counter()
	count_locs = counter()
	count_pops = counter()
	count_poploc = counter()
	acc = 0
	for (loc, pop) in cities:
		acc = (acc + pop * (loc * count_cities.count(None, pop) - count_locs.count(None, pop)) + loc * count_pops.count(pop + 1, None) - count_poploc.count(pop + 1, None)) % MOD
		count_cities.increment(pop, 1)
		count_locs.increment(pop, loc)
		count_pops.increment(pop, pop)
		count_poploc.increment(pop, pop * loc)
	return acc

def test(num=None):
	if num is None:
		inp = sys.stdin
		out = sys.stdout
	else:
		inp = open('./input' + num + '.txt')
		out = open('./myoutput' + num + '.txt', 'w')
	start_time = time()
	T = int(inp.readline())
	sizes = []
	for _ in range(T):
		N = int(inp.readline())
		sizes.append(N)
		locs = list(map(int, inp.readline().strip().split(' ')))
		pops = list(map(int, inp.readline().strip().split(' ')))
		print(process(N, locs, pops), file=out)
	end_time = time()
	if num is not None:
		inp.close()
		if num != '00':
			remove_chars = len(linesep)
			out.truncate(out.tell() - remove_chars)
		out.close()
		succeeded = cmp('myoutput' + num + '.txt', 'output' + num + '.txt')
		outcome = '  Success' if succeeded else '  Failure'
		print('#' + num + outcome, 'in {:f}s'.format(end_time - start_time))
test()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = fenpiece()
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class City(object):
	__slots__ = ['x_sum', 'p_sum', 'xp_sum', 'cnt']

	def __init__(self, x_sum=0, p_sum=0, xp_sum=0, cnt=0):
		self.x_sum = x_sum
		self.p_sum = p_sum
		self.xp_sum = xp_sum
		self.cnt = cnt

	def __iadd__(self, other):
		self.x_sum += other.x_sum
		self.p_sum += other.p_sum
		self.xp_sum += other.xp_sum
		self.cnt += other.cnt
		return self

	def __add__(self, other):
		ret = City()
		ret.__iadd__(self)
		ret.__iadd__(other)
		return ret

	def __sub__(self, other):
		ret = City()
		ret.__iadd__(self)
		ret.x_sum -= other.x_sum
		ret.p_sum -= other.p_sum
		ret.xp_sum -= other.xp_sum
		ret.cnt -= other.cnt
		return ret

	def get(self):
		return (self.x_sum, self.p_sum, self.xp_sum, self.cnt)

def init():
	return [City() for _ in range(10001)]

def add(bit, x, p):
	elm = City(x, p, x * p, 1)
	idx = p
	while idx < 10001:
		bit[idx] += elm
		idx += idx & -idx

def get(bit, p):
	res = City()
	idx = p
	while idx > 0:
		res += bit[idx]
		idx -= idx & -idx
	return res

def list_input():
	return list(map(int, input().strip().split()))
for _ in range(int(input())):
	bit = init()
	N = int(input())
	xs = list_input()
	ps = list_input()
	sum_total_cities = City()
	res = 0
	for (x, p) in sorted(zip(xs, ps)):
		sum_small_cities = get(bit, p)
		sum_larger_cities = sum_total_cities - sum_small_cities
		res += p * (sum_small_cities.cnt * x - sum_small_cities.x_sum)
		res += x * sum_larger_cities.p_sum - sum_larger_cities.xp_sum
		add(bit, x, p)
		sum_total_cities += City(x, p, x * p, 1)
	print(res % 1000000007)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	fenlist = [fenpiece() for i in range(pBound)]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class Fenwick_tree:

	def __init__(self, n):
		sz = 1
		while n >= sz:
			sz *= 2
		self.size = sz
		self.data = [0] * sz

	def sum(self, i):
		if i <= 0:
			return 0
		s = 0
		while i >= 0:
			s += self.data[i]
			i = (i & i + 1) - 1
		return s

	def sumrange(self, lo, hi):
		return self.sum(hi - 1) - self.sum(lo - 1)

	def add(self, i, x):
		assert i > 0
		while i < self.size:
			self.data[i] += x
			i |= i + 1

def get_lookup(arr):
	(value_to_idx, idx_to_value) = ({}, {})
	arr.sort()
	idx = 1
	for i in arr:
		if i not in value_to_idx:
			value_to_idx[i] = idx
			idx_to_value[idx] = i
			idx += 1
	return (value_to_idx, idx_to_value)
mod = 10 ** 9 + 7
for case in range(int(input())):
	N = int(input())
	C = list(map(int, input().split()))
	P = list(map(int, input().split()))
	arr = list(sorted(((c, p) for (p, c) in zip(P, C))))
	(cvi, civ) = get_lookup(C)
	(pvi, piv) = get_lookup(P)
	(tpd, tpn) = (Fenwick_tree(N + 1), Fenwick_tree(N + 1))
	(tpdp, tpp) = (Fenwick_tree(N + 1), Fenwick_tree(N + 1))
	ans = 0
	for (c, p) in arr:
		(ci, pi) = (cvi[c], pvi[p])
		num_cit = tpn.sum(pi)
		sum_cit = tpd.sum(pi)
		ans = (ans + (num_cit * c - sum_cit) * p) % mod
		sumprod_cit = tpdp.sumrange(pi + 1, N + 1)
		sum_pop = tpp.sumrange(pi + 1, N + 1)
		ans = (ans + sum_pop * c - sumprod_cit) % mod
		tpn.add(pi, 1)
		tpd.add(pi, c)
		tpdp.add(pi, c * p)
		tpp.add(pi, p)
	print(ans)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


import math
import os
import random
import re
import sys

class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


from bisect import bisect_left

class Shell:

	def __init__(self, distances):
		self.size = sum(distances)
		self.list = distances
		self.elements = len(self.list)

	def __str__(self):
		return '({}, {})'.format(self.size, self.list)

	def FindValue(self, value):
		i = bisect_left(self.list, value)
		return i if self.elements != i and self.list[i] == value else None

	def DestroyElement(self, element):
		v = self.list.pop(element)
		self.size -= v
		self.elements -= 1
		return self.size == 0

	def Sum(self, element):
		leftSum = self.list[element] * element - sum(self.list[0:element])
		rightSum = sum(self.list[element + 1:]) - (self.elements - element - 1) * self.list[element]
		return leftSum + rightSum

	def GetSize(self, element):
		return self.list[element]

	def CalculateBeforeSize(self, size):
		return size * self.elements - self.size

	def CalculateAfterSize(self, size):
		return self.size - size * self.elements

	def __lt__(self, other):
		return self.list[self.elements - 1] < other

class DistanceList:

	def __init__(self, distances):
		numShells = min(int(len(distances) / 3000) + 1, 16)
		perShell = int(len(distances) / numShells)
		additional = len(distances) % numShells
		self.shells = list()
		curShell = 0
		for i in range(numShells):
			plus1 = 1 if additional > 0 else 0
			nextShell = curShell + perShell + plus1
			self.shells.append(Shell(distances[curShell:nextShell]))
			curShell = nextShell
			additional -= 1

	def FindValue(self, value):
		s = bisect_left(self.shells, value)
		return (s, self.shells[s].FindValue(value))

	def DestroyElement(self, element):
		if self.shells[element[0]].DestroyElement(element[1]):
			self.shells.pop(element[0])

	def CalculateDistance(self, element):
		citySize = self.shells[element[0]].GetSize(element[1])
		distanceBefore = 0
		for s in self.shells[:element[0]]:
			distanceBefore += s.CalculateBeforeSize(citySize)
		distanceAfter = 0
		for s in self.shells[element[0] + 1:]:
			distanceAfter += s.CalculateAfterSize(citySize)
		return distanceBefore + distanceAfter + self.shells[element[0]].Sum(element[1])

	def __str__(self):
		return '\n'.join([str(s) for s in self.shells])

class DistanceFinder:

	def __init__(self, distances):
		self.distanceList = DistanceList(sorted(distances))

	def CalculateDistance(self, value):
		element = self.distanceList.FindValue(value)
		distance = self.distanceList.CalculateDistance(element)
		self.distanceList.DestroyElement(element)
		return distance

	def Print(self):
		print(str(self.distanceList))

def CalculateCable(distances, populations):
	totalDistance = 0
	sortedPop = sorted(zip(distances, populations), key=lambda x: x[1], reverse=True)
	df = DistanceFinder(distances)
	for (distance, population) in sortedPop:
		totalDistance += df.CalculateDistance(distance) * population
	print(totalDistance % 1000000007)
tests = int(input())
for t in range(tests):
	cities = int(input())
	distances = list(map(int, input().split()))
	populations = list(map(int, input().split()))
	CalculateCable(distances, populations)


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


import sys

class Node:

	def __init__(self, mini, maxi):
		self.sumAbs = 0
		self.min = mini
		self.max = maxi
		self.leftSon = 0
		self.rightSon = 0
		self.numCities = 0

class Tree:

	def __init__(self, table):
		self.listNode = []
		self.root = self.merge(table, 0, len(table) - 1)

	def merge(self, table, i, j):
		if i == j:
			self.listNode.append(Node(table[i], table[i]))
			return len(self.listNode) - 1
		else:
			index = len(self.listNode)
			self.listNode.append(Node(table[i], table[j]))
			mid = (i + j) // 2
			fg = self.merge(table, i, mid)
			fd = self.merge(table, mid + 1, j)
			self.listNode[index].leftSon = fg
			self.listNode[index].rightSon = fd
			return index

	def insert(self, abscisse, pop):
		result = 0
		actualNode = self.listNode[self.root]
		actualNode.sumAbs += abscisse
		actualNode.numCities += 1
		while actualNode.min != actualNode.max:
			if self.listNode[actualNode.leftSon].max < abscisse:
				otherNode = self.listNode[actualNode.leftSon]
				actualNode = self.listNode[actualNode.rightSon]
				result += otherNode.numCities * abscisse - otherNode.sumAbs
			else:
				otherNode = self.listNode[actualNode.rightSon]
				actualNode = self.listNode[actualNode.leftSon]
				result += otherNode.sumAbs - otherNode.numCities * abscisse
			actualNode.sumAbs += abscisse
			actualNode.numCities += 1
		return result

def mapPopCities(n, pos, pop):
	result = []
	for i in range(n):
		result.append((pop[i], pos[i]))
	return result

def solve():
	result = 0
	numCities = int(sys.stdin.readline())
	positions = list(map(int, sys.stdin.readline().split()))
	pop = list(map(int, sys.stdin.readline().split()))
	mapPopulations = mapPopCities(numCities, positions, pop)
	positions.sort()
	myTree = Tree(positions)
	mapPopulations.sort()
	for (pop, pos) in mapPopulations:
		tmp = myTree.insert(pos, pop)
		result += pop * tmp
	print(result % 1000000007)
numTest = int(sys.stdin.readline())
for _ in range(numTest):
	solve()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()


class fenpiece:
	__slots__ = ['x', 'p', 'px', 'c']

	def __init__(self, x=0, p=0, px=0, c=0):
		self.x = x
		self.p = p
		self.px = px
		self.c = c

	def __iadd__(self, other):
		self.x += other.x
		self.p += other.p
		self.px += other.px
		self.c += other.c
		return self

	def __radd__(self, other):
		return fenpiece(self.x, self.p, self.px, self.c)

	def __sub__(self, other):
		return fenpiece(self.x - other.x, self.p - other.p, self.px - other.px, self.c - other.c)

def fensum(seq, i):
	sum = 0
	while i:
		sum += seq[i - 1]
		i -= i & -i
	return sum

def fensumrange(seq, i, j):
	return fensum(seq, j) - fensum(seq, i)

def fenadd(seq, i, v):
	i += 1
	bound = len(seq) + 1
	while i < bound:
		seq[i - 1] += v
		i += i & -i
pBound = 10001
magicmod = 1000000007
fenlist = [fenpiece() for i in range(pBound)]
T = int(input())
for t in range(T):
	total = 0
	N = int(input())
	X = [int(s) for s in input().split()]
	P = [int(s) for s in input().split()]
	cities = sorted(zip(X, P))
	cable = 0
	for (x, p) in cities:
		underP = fensum(fenlist, p)
		overP = fensumrange(fenlist, p, pBound)
		cable = (cable + p * (underP.c * x - underP.x) + overP.p * x - overP.px) % magicmod
		fenadd(fenlist, p, fenpiece(x, p, x * p, 1))
	print(cable)
	for f in fenlist:
		f.__init__()