You are playing a computer game. In this game, you have to fight $n$ monsters.

To defend from monsters, you need a shield. Each shield has two parameters: its current durability $a$ and its defence rating $b$. Each monster has only one parameter: its strength $d$.

When you fight a monster with strength $d$ while having a shield with current durability $a$ and defence $b$, there are three possible outcomes:  if $a = 0$, then you receive $d$ damage;  if $a > 0$ and $d \ge b$, you receive no damage, but the current durability of the shield decreases by $1$;  if $a > 0$ and $d < b$, nothing happens. 

The $i$-th monster has strength $d_i$, and you will fight each of the monsters exactly once, in some random order (all $n!$ orders are equiprobable). You have to consider $m$ different shields, the $i$-th shield has initial durability $a_i$ and defence rating $b_i$. For each shield, calculate the expected amount of damage you will receive if you take this shield and fight the given $n$ monsters in random order.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the number of monsters and the number of shields, respectively.

The second line contains $n$ integers $d_1$, $d_2$, ..., $d_n$ ($1 \le d_i \le 10^9$), where $d_i$ is the strength of the $i$-th monster.

Then $m$ lines follow, the $i$-th of them contains two integers $a_i$ and $b_i$ ($1 \le a_i \le n$; $1 \le b_i \le 10^9$) — the description of the $i$-th shield.


-----Output-----

Print $m$ integers, where the $i$-th integer represents the expected damage you receive with the $i$-th shield as follows: it can be proven that, for each shield, the expected damage is an irreducible fraction $\dfrac{x}{y}$, where $y$ is coprime with $998244353$. You have to print the value of $x \cdot y^{-1} \bmod 998244353$, where $y^{-1}$ is the inverse element for $y$ ($y \cdot y^{-1} \bmod 998244353 = 1$).


-----Examples-----
Input
3 2
1 3 1
2 1
1 2

Output
665496237
1

Input
3 3
4 2 6
3 1
1 2
2 3

Output
0
8
665496236

Difficulty: VERY_HARD
Tags: Sorting

Combinatorics

Probability
Skill types: Sorting

Starter code:

Solutions:
import sys, bisect
input = sys.stdin.readline
MOD = 998244353

def frac(a, b):
	return a * pow(b, MOD - 2, MOD) % MOD
(n, m) = map(int, input().split())
d = sorted(list(map(int, input().split())))
tot = sum(d)
pref = [0]
for v in d:
	pref.append(pref[-1] + v)
out = [0] * m
for _ in range(m):
	(a, b) = map(int, input().split())
	ind = bisect.bisect_left(d, b)
	sum_before = pref[ind]
	rest = tot - pref[ind]
	if a <= n - ind:
		out[_] += sum_before * frac(n - ind - a + 1, n - ind + 1)
		out[_] += rest * frac(n - ind - a, n - ind)
		out[_] %= MOD
print('\n'.join(map(str, out)))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import bisect
mod = 998244353

def fpow(a, b):
	ans = 1
	while b:
		if b & 1:
			ans = ans * a % mod
		b >>= 1
		a = a * a % mod
	return ans
(n, m) = map(int, input().split())
d = list(map(int, input().split()))
d = sorted(d)
pre = [0 for _ in range(n + 1)]
for i in range(n):
	pre[i + 1] = pre[i] + d[i]
for _ in range(m):
	(a, b) = map(int, input().split())
	k = bisect.bisect_left(d, b)
	low = max(0, n - k - a)
	upp = max(0, n - k - a + 1)
	print((low * fpow(n - k, mod - 2) * (pre[n] - pre[k] + mod) % mod + upp * fpow(n - k + 1, mod - 2) * pre[k] % mod) % mod)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import bisect
(n, m) = map(int, input().split())
MOD = 998244353

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	if g != 1:
		return 0
	else:
		return x % m
d = list(map(int, input().split()))
d.sort()
dSum = [0]
for elem in d:
	dSum.append(dSum[-1] + elem)
ans = [0] * m
for _ in range(m):
	(a, b) = map(int, input().split())
	l = bisect.bisect_left(d, b)
	l -= 1
	ans[_] = (dSum[l + 1] * max(n - l - a, 0) * modinv(n - l, MOD) + (dSum[-1] - dSum[l + 1]) * max(n - l - 1 - a, 0) * modinv(n - l - 1, MOD)) % MOD
print('\n'.join(map(str, ans)))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	import bisect
	(n, m) = map(int, input().split())
	MOD = 998244353

	def egcd(a, b):
		if a == 0:
			return (b, 0, 1)
		else:
			(g, y, x) = egcd(b % a, a)
			return (g, x - b // a * y, y)

	def modinv(a, m):
		(g, x, y) = egcd(a, m)
		if g != 1:
			raise Exception("Modular Inverse doesn't exist")
		else:
			return x % m
	d = list(map(int, input().split()))
	d.sort()
	dSum = [0]
	for elem in d:
		dSum.append(dSum[-1] + elem)
	ans = [0] * m
	from math import gcd
	for _ in range(m):
		(a, b) = map(int, input().split())
		l = bisect.bisect_left(d, b)
		l -= 1
		if n != l and n != l + 1:
			ans[_] = (dSum[l + 1] * max(n - l - a, 0) * modinv(n - l, MOD) + (dSum[-1] - dSum[l + 1]) * max(n - l - 1 - a, 0) * modinv(n - l - 1, MOD)) % MOD
	print('\n'.join(map(str, ans)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, bisect
r = lambda : map(int, sys.stdin.readline().split())
M = 998244353

def f(b):
	return pow(b, M - 2, M)
(n, m) = r()
d = sorted(r())
p = [0]
for v in d:
	p += [p[-1] + v]
for _ in range(m):
	(a, b) = r()
	i = bisect.bisect_left(d, b)
	v = n - i
	print([(p[i] * a * f(v + v * v) - p[-1] * (a * f(v) - 1)) % M, 0][a > v])


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	res = []
	for (ch, g) in groupby(it):
		res.append((ch, len(list(g))))
	return res

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	mod = 998244353
	(n, m) = RL()
	d = RLL()
	d.sort()
	pre = [0]
	for i in range(n):
		pre.append((pre[-1] + d[i]) % mod)
	ans = pre[-1]
	for i in range(m):
		(a, b) = RL()
		ind = bisect_left(d, b)
		big = n - ind
		if big < a:
			print(0)
			continue
		cur = ans - (ans - pre[ind]) * a % mod * pow(big, mod - 2, mod) % mod - pre[ind] * a * pow(big + 1, mod - 2, mod) % mod
		cur %= mod
		print(cur)


import sys
input = sys.stdin.readline
mod = 998244353

def frac(limit):
	frac = [1] * limit
	for i in range(2, limit):
		frac[i] = i * frac[i - 1] % mod
	fraci = [None] * limit
	fraci[-1] = pow(frac[-1], mod - 2, mod)
	for i in range(-2, -limit - 1, -1):
		fraci[i] = fraci[i + 1] * (limit + i + 1) % mod
	return (frac, fraci)

def mul(a, b):
	return a % mod * (b % mod) % mod

def div(a, b):
	return mul(a, pow(b, mod - 2, mod))
(N, M) = list(map(int, input().split()))
X = list(map(int, input().split()))
t = []
for i in range(N):
	t.append((0, X[i]))
Q = []
for i in range(M):
	(a, b) = list(map(int, input().split()))
	Q.append((a, b))
	t.append((1, b))
Y = [0] * (N + M)
Z = [0] * (N + M)
t.sort(key=lambda x: x[1])
d = dict()
d2 = [0] * (N + M)
cnt = 0
for (l, x) in t:
	if x not in d:
		cnt += 1
		d[x] = cnt
		d2[cnt] = x
	if not l:
		Y[cnt] += 1
for i in range(N + M):
	Z[i] = Y[i] * d2[i]
Y.append(0)
Z.append(0)
for i in range(N + M - 1, -1, -1):
	Y[i] = Y[i + 1] + Y[i]
	Z[i] = Z[i + 1] + Z[i]
for (a, b) in Q:
	k = Y[d[b]]
	R = 0
	if k > a:
		R += div(k - a, k) * Z[d[b]]
	if k + 1 > a:
		R += div(k + 1 - a, k + 1) * (Z[0] - Z[d[b]])
	print(R % mod)


import io
import os
from bisect import bisect_left
from fractions import Fraction
MOD = 998244353

def modInverse(a, p=MOD):
	return pow(a, p - 2, p)

def solve(N, M, D, AB):
	assert len(D) == N
	assert len(AB) == M
	D.sort()
	pref = [0]
	for x in D:
		pref.append(pref[-1] + x)
	maxDamage = Fraction(sum(D))
	ans = []
	for (a, b) in AB:
		numFreeBlocks = bisect_left(D, b)
		numDrainBlocks = N - numFreeBlocks
		if numDrainBlocks < a:
			ans.append(0)
			continue
		totalDrainBlock = pref[N] - pref[numFreeBlocks]
		expectedDrainBlock = totalDrainBlock * Fraction(a, numDrainBlocks)
		totalFreeBlock = pref[numFreeBlocks]
		expectedFreeBlock = totalFreeBlock * Fraction(a, numDrainBlocks + 1)
		expectedDamage = maxDamage - expectedDrainBlock - expectedFreeBlock
		ans.append(expectedDamage.numerator * modInverse(expectedDamage.denominator) % MOD)
	return '\n'.join(map(str, ans))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, M) = [int(x) for x in input().split()]
D = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for i in range(M)]
ans = solve(N, M, D, AB)
print(ans)


from fractions import Fraction
import sys
input = sys.stdin.readline
d = dict()

def find(L, n):
	if n in d:
		return d[n]
	lo = 0
	hi = len(L)
	while lo < hi:
		mid = (lo + hi) // 2
		if L[mid] < n:
			lo = mid + 1
		else:
			hi = mid
	d[n] = lo
	return lo
mod = 998244353
(n, m) = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
sumL = [0]
for i in L:
	sumL.append((sumL[-1] + i) % mod)
for i in ' ' * m:
	(a, b) = map(int, input().split())
	pt = find(L, b)
	totsum = sumL[-1]
	lesssum = sumL[pt]
	moresum = (totsum - lesssum) % mod
	if n - pt < a:
		print(0)
		continue
	c = Fraction(lesssum * (n - pt - a + 1) % mod, n - pt + 1) + Fraction(moresum * (n - pt - a) % mod, n - pt)
	p = c.numerator % mod
	q = c.denominator % mod
	print(p * pow(q, mod - 2, mod) % mod)


import sys
input = sys.stdin.readline
mod = 998244353
NNN = 2 * 10 ** 5 + 1
inverse = [0, 1]
for i in range(2, NNN + 1):
	inverse.append(-inverse[mod % i] * (mod // i) % mod)

def div(a, b):
	return a * inverse[b]
(N, M) = map(int, input().split())
X = list(map(int, input().split()))
t = []
for i in range(N):
	t.append((0, X[i]))
Q = []
for i in range(M):
	(a, b) = map(int, input().split())
	Q.append((a, b))
	t.append((1, b))
Y = [0] * (N + M)
Z = [0] * (N + M)
t.sort(key=lambda x: x[1])
d = dict()
d2 = [0] * (N + M)
cnt = 0
for (l, x) in t:
	if x not in d:
		cnt += 1
		d[x] = cnt
		d2[cnt] = x
	if not l:
		Y[cnt] += 1
for i in range(N + M):
	Z[i] = Y[i] * d2[i]
Y.append(0)
Z.append(0)
for i in range(N + M - 1, -1, -1):
	Y[i] = Y[i + 1] + Y[i]
	Z[i] = Z[i + 1] + Z[i]
for (a, b) in Q:
	k = Y[d[b]]
	R = 0
	if k > a:
		R += div(k - a, k) * Z[d[b]]
	if k + 1 > a:
		R += div(k + 1 - a, k + 1) * (Z[0] - Z[d[b]])
	print(R % mod)


from bisect import bisect_left
import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def prog():
	mod = 998244353
	(n, m) = map(int, input().split())
	d = list(map(int, input().split()))
	d.sort()
	dsum = [0]
	for i in d:
		dsum.append(dsum[-1] + i)
	for i in range(m):
		(a, b) = map(int, input().split())
		loc = bisect_left(d, b)
		if n - loc < a:
			print(0)
			continue
		ans = 0
		ans += (dsum[n] - dsum[loc]) * (n - loc - a) * pow(n - loc, mod - 2, mod)
		ans += dsum[loc] * (n - loc - a + 1) * pow(n - loc + 1, mod - 2, mod)
		print((ans % mod + mod) % mod)
prog()


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [X[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [X[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=None):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		self.mod = mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matrix[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matrix[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matrix[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] + other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matrix[i][j] - other._matrix[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matrix[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matrix[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matrix[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)

class SegmentTree:

	def __init__(self, init_val, segfunc, ide_ele):
		n = len(init_val)
		self.segfunc = segfunc
		self.ide_ele = ide_ele
		self.num = 1 << (n - 1).bit_length()
		self.tree = [ide_ele] * 2 * self.num
		for i in range(n):
			self.tree[self.num + i] = init_val[i]
		for i in range(self.num - 1, 0, -1):
			self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

	def update(self, k, x):
		k += self.num
		self.tree[k] = x
		while k > 1:
			self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
			k >>= 1

	def query(self, l, r):
		res = self.ide_ele
		l += self.num
		r += self.num
		while l < r:
			if l & 1:
				res = self.segfunc(res, self.tree[l])
				l += 1
			if r & 1:
				res = self.segfunc(res, self.tree[r - 1])
			l >>= 1
			r >>= 1
		return res

	def bisect_l(self, l, r, x):
		l += self.num
		r += self.num
		Lmin = -1
		Rmin = -1
		while l < r:
			if l & 1:
				if self.tree[l] <= x and Lmin == -1:
					Lmin = l
				l += 1
			if r & 1:
				if self.tree[r - 1] <= x:
					Rmin = r - 1
			l >>= 1
			r >>= 1
		if Lmin != -1:
			pos = Lmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		elif Rmin != -1:
			pos = Rmin
			while pos < self.num:
				if self.tree[2 * pos] <= x:
					pos = 2 * pos
				else:
					pos = 2 * pos + 1
			return pos - self.num
		else:
			return -1
from heapq import heappush, heappop

class MinCostFlow:
	INF = 10 ** 18

	def __init__(self, N):
		self.N = N
		self.G = [[] for i in range(N)]

	def add_edge(self, fr, to, cap, cost):
		forward = [to, cap, cost, None]
		backward = forward[3] = [fr, 0, -cost, forward]
		self.G[fr].append(forward)
		self.G[to].append(backward)

	def flow(self, s, t, f):
		N = self.N
		G = self.G
		INF = MinCostFlow.INF
		res = 0
		H = [0] * N
		prv_v = [0] * N
		prv_e = [None] * N
		d0 = [INF] * N
		dist = [INF] * N
		while f:
			dist[:] = d0
			dist[s] = 0
			que = [(0, s)]
			while que:
				(c, v) = heappop(que)
				if dist[v] < c:
					continue
				r0 = dist[v] + H[v]
				for e in G[v]:
					(w, cap, cost, _) = e
					if cap > 0 and r0 + cost - H[w] < dist[w]:
						dist[w] = r = r0 + cost - H[w]
						prv_v[w] = v
						prv_e[w] = e
						heappush(que, (r, w))
			if dist[t] == INF:
				return None
			for i in range(N):
				H[i] += dist[i]
			d = f
			v = t
			while v != s:
				d = min(d, prv_e[v][1])
				v = prv_v[v]
			f -= d
			res += d * H[t]
			v = t
			while v != s:
				e = prv_e[v]
				e[1] -= d
				e[3][1] += d
				v = prv_v[v]
		return res
mod = 998244353
N = 2 * 10 ** 5 + 100
g1 = [1] * (N + 1)
g2 = [1] * (N + 1)
inverse = [1] * (N + 1)
for i in range(2, N + 1):
	g1[i] = g1[i - 1] * i % mod
	inverse[i] = -inverse[mod % i] * (mod // i) % mod
	g2[i] = g2[i - 1] * inverse[i] % mod
inverse[0] = 0
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.buffer.readline()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
mod = 998244353
(n, m) = mi()
if 1:
	D = li()
	shield = [tuple(mi()) for i in range(m)]
else:
	D = [random.randint(0, 10 ** 9) for i in range(n)]
	shield = [(random.randint(0, n), random.randint(0, 10 ** 9)) for i in range(m)]
val = set([d for d in D] + [b for (a, b) in shield])
val = sorted(list(val))
comp = {v: i + 1 for (i, v) in enumerate(val)}
num = len(comp)
bit_sum = BIT(num, mod=998244353)
bit_cnt = BIT(num, mod=998244353)
for d in D:
	idx = comp[d]
	bit_sum.update(idx, d)
	bit_cnt.update(idx, 1)
S = sum(D) % mod
for (a, b) in shield:
	idx = comp[b]
	small = bit_sum.query(idx - 1)
	big = (S - small) % mod
	y = bit_cnt.query(idx - 1)
	x = n - y
	if not x:
		res = 0
	else:
		res = big * max(x - a, 0) * inverse[x]
		res += small * max(x - a + 1, 0) * inverse[x + 1]
		res %= mod
	print(res)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Comb:

	def __init__(self, n, mo=10 ** 9 + 7):
		self.fac = [0] * (n + 1)
		self.inv = [1] * (n + 1)
		self.fac[0] = 1
		self.fact(n)
		for i in range(1, n + 1):
			self.fac[i] = i * self.fac[i - 1] % mo
			self.inv[n] *= i
			self.inv[n] %= mo
		self.inv[n] = pow(self.inv[n], mo - 2, mo)
		for i in range(1, n):
			self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
		return

	def fact(self, n):
		return self.fac[n]

	def invf(self, n):
		return self.inv[n]

	def comb(self, x, y):
		if y < 0 or y > x:
			return 0
		return self.fac[x] * self.inv[x - y] * self.inv[y] % mo
show_flg = False
show_flg = True
ans = 0
mo = 998244353
ans = 0
(n, m) = LI()
d = sorted(LI())
ad = accum(d)
for i in range(m):
	(a, b) = LI()
	k = n - bisect.bisect_left(d, b)
	x = n - k
	ans = 0
	if a > k:
		ans = 0
	else:
		ans = ((k + 1) * (k - a) * (ad[n] - ad[x]) + (k + 1 - a) * k * ad[x]) % mo
		ans *= pow((k + 1) * k, mo - 2, mo)
	print(ans % mo)


import sys, bisect
M = 998244353
y = lambda : map(int, sys.stdin.readline().split())
(n, m) = y()
d = sorted(y())
p = [0]
for i in d:
	p += [p[-1] + i]
for _ in range(m):
	(a, b) = y()
	i = bisect.bisect_left(d, b)
	print(0 if n - i < a else ((n - i - a + 1) * p[i] * pow(n - i + 1, M - 2, M) + (n - i - a) * (p[-1] - p[i]) * pow(n - i, M - 2, M)) % M)


import sys
from sys import stdin
import bisect

def inverse(a, mod):
	return pow(a, mod - 2, mod)

def modfac(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def modnCr(n, r):
	return fac[n] * inv[n - r] * inv[r] % mod
mod = 998244353
(fac, inv) = modfac(3 * 10 ** 5, mod)
(n, m) = map(int, stdin.readline().split())
d = list(map(int, stdin.readline().split()))
d.sort()
dsum = sum(d)
s = [0]
for i in range(n):
	s.append(s[-1] + d[i])
aaa = []
for loop in range(m):
	(a, b) = map(int, stdin.readline().split())
	X = bisect.bisect_left(d, b)
	Y = n - X
	xsum = s[X]
	ysum = dsum - xsum
	ans = 0
	if a <= Y:
		ans += ysum * fac[n] * (Y - a) * inverse(Y, mod)
		ans += xsum * fac[n] * (Y - a + 1) * inverse(Y + 1, mod)
		ans %= mod
	aaa.append(ans * inv[n] % mod)
print('\n'.join(map(str, aaa)))


MOD = 998244353
import sys
from fractions import Fraction
(n, m) = [int(e) for e in sys.stdin.readline().split(' ')]
strengths = [int(e) for e in sys.stdin.readline().split(' ')]
defs = []
durs = []
for _ in range(m):
	(du, de) = [int(e) for e in sys.stdin.readline().split(' ')]
	defs.append(de)
	durs.append(du)
strengths = list(reversed(sorted(strengths)))
prefs = [0]
for i in range(0, len(strengths)):
	prefs.append(prefs[-1] + strengths[i])

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def find_strength(x):
	if x > strengths[0]:
		return 0
	if x <= strengths[-1]:
		return len(strengths)
	lo = 0
	hi = len(strengths) - 1
	mid = 0
	while lo != hi:
		mid = (hi + lo) // 2
		if strengths[mid] >= x:
			if mid + 1 >= len(strengths):
				return len(strengths)
			if strengths[mid + 1] < x:
				return mid + 1
			lo = mid + 1
		elif strengths[mid] < x:
			hi = mid - 1
	return lo + 1

def calculate(a, b):
	k = find_strength(b)
	if a > k:
		return Fraction(0, 1)
	bad_m = Fraction(prefs[k], 1) * (Fraction(1, 1) - Fraction(a, k))
	good_m = Fraction(prefs[n] - prefs[k], 1) * (Fraction(1, 1) - Fraction(a, k + 1))
	return bad_m + good_m
for x in range(m):
	(a, b) = (durs[x], defs[x])
	F = calculate(a, b)
	(P, Q) = (F.numerator, F.denominator)
	sys.stdout.write(str(P * modInverse(Q, MOD) % MOD) + '\n')


import bisect
import sys
input = sys.stdin.readline

def inv(x):
	return pow(x, 998244351, 998244353)
l = input().split()
n = int(l[0])
m = int(l[1])
l = input().split()
li = [int(i) for i in l]
li.sort()
pref = []
sumi = 0
for i in range(n):
	sumi += li[i]
	pref.append(sumi)
for i in range(m):
	ans = 0
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	z = bisect.bisect_left(li, b)
	y = n - z
	k = max(y - a, 0)
	if y == 0:
		print(0)
		continue
	if z > 0:
		ala = sumi - pref[z - 1]
	else:
		ala = sumi
	ans = ans + ala * k * inv(y)
	ans %= 998244353
	k = max(y + 1 - a, 0)
	if z > 0:
		ala = pref[z - 1]
	else:
		ala = 0
	ans = ans + ala * k * inv(y + 1)
	ans %= 998244353
	print(ans)


import sys
from bisect import bisect_left
from collections import defaultdict
import random
from math import gcd
input = sys.stdin.readline
flush = sys.stdout.flush
get_int = lambda : int(input().rstrip())
get_arr = lambda : [int(w) for w in input().split()]
get_str = lambda : input().rstrip()
mod = 998244353
(n, m) = get_arr()
ds = sorted(get_arr())
sds = sum(ds) % mod
ps = [0]
for d in ds:
	ps.append((ps[-1] + d) % mod)
get_sum = lambda l, r: ps[r + 1] - ps[l]
for _ in range(m):
	(a, b) = get_arr()
	ind = bisect_left(ds, b)
	t = n - ind
	if a > t:
		print(0)
		continue
	ans = pow(t, -1, mod) * get_sum(ind, n - 1)
	ans = (ans + pow(t + 1, -1, mod) * get_sum(0, ind - 1)) % mod
	print((sds - a * ans) % mod)


import sys, bisect
input = sys.stdin.readline
MOD = 998244353

def f(a, b):
	return a * pow(b, MOD - 2, MOD)
(n, m) = map(int, input().split())
d = sorted(map(int, input().split()))
pref = [0]
for v in d:
	pref.append(pref[-1] + v)
out = [0] * m
for _ in range(m):
	(a, b) = map(int, input().split())
	i = bisect.bisect_left(d, b)
	if a <= n - i:
		out[_] = (pref[i] * f(n - i - a + 1, n - i + 1) + (pref[-1] - pref[i]) * f(n - i - a, n - i)) % MOD
print('\n'.join(map(str, out)))


mod = 998244353
eps = 10 ** (-9)

def main():
	import sys
	from bisect import bisect_left
	input = sys.stdin.buffer.readline
	(N, M) = map(int, input().split())
	D = list(map(int, input().split()))
	D.sort()
	cs = [0] * (N + 1)
	for i in range(N):
		cs[i + 1] = (cs[i] + D[i]) % mod
	ans = [0] * M
	for m in range(M):
		(a, b) = map(int, input().split())
		i = bisect_left(D, b)
		if i == N:
			ans[m] = 0
			continue
		k = N - i
		if a > k:
			ans[m] = 0
			continue
		ans[m] = ((cs[-1] - cs[i]) % mod * ((k - a) * pow(k, mod - 2, mod)) % mod % mod + cs[i] * (k + 1 - a) % mod * pow(k + 1, mod - 2, mod) % mod) % mod
	print(*ans, sep='\n')
main()


import sys, io, os, bisect
z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = 998244353
y = lambda : map(int, z().split())
(n, m) = y()
d = sorted(y())
p = [0]
for i in d:
	p += [p[-1] + i]
for _ in range(m):
	(a, b) = y()
	i = bisect.bisect_left(d, b)
	print(0 if n - i < a else ((n - i - a + 1) * p[i] * pow(n - i + 1, M - 2, M) + (n - i - a) * (p[-1] - p[i]) * pow(n - i, M - 2, M)) % M)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import bisect
(n, m) = map(int, input().split())
MOD = 998244353

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a, m):
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception("Modular Inverse doesn't exist")
	else:
		return x % m
d = list(map(int, input().split()))
d.sort()
dSum = [0]
for elem in d:
	dSum.append(dSum[-1] + elem)
ans = [0] * m
from math import gcd
for _ in range(m):
	(a, b) = map(int, input().split())
	l = bisect.bisect_left(d, b)
	l -= 1
	if n != l and n != l + 1:
		ans[_] = (dSum[l + 1] * max(n - l - a, 0) * modinv(n - l, MOD) + (dSum[-1] - dSum[l + 1]) * max(n - l - 1 - a, 0) * modinv(n - l - 1, MOD)) % MOD
print('\n'.join(map(str, ans)))


import sys, bisect
r = lambda : sys.stdin.readline().split()
M = 998244353
(n, m) = map(int, r())
d = [int(x) for x in r()]
d.sort()
suf = [x for x in d]
i = n - 1
for i in range(n - 2, -1, -1):
	suf[i] += suf[i + 1]
while m > 0:
	m -= 1
	(a, b) = map(int, r())
	l = bisect.bisect_left(d, b)
	g = n - l
	if g < a:
		print(0)
	else:
		print((suf[l] * (g - a) * pow(g, M - 2, M) + pow(g + 1, M - 2, M) * (g + 1 - a) * (suf[0] - suf[l])) % M)