#include <bits/stdc++.h>
constexpr long long MOD = 998244353LL;
using namespace std;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long pw(long long x, int n, long long mod) {
  long long ans = 1LL;
  for (; n > 0; n >>= 1) {
    if (n & 1) {
      ans = (ans * x) % mod;
    }
    x = (x * x) % mod;
  }
  return ans;
}
long long mod_inv(long long x) { return pw(x, MOD - 2, MOD) % MOD; }
long long sum(int l, int r, vector<long long> &prefix) {
  long long ans = r >= 0 ? prefix[r] : 0LL;
  if (l > 0) {
    ans -= prefix[l - 1];
  }
  return (ans + MOD) % MOD;
}
long long get_damage(int a, int b, vector<int> &mons, int n,
                     vector<long long> &prefix) {
  int k = mons.end() - lower_bound(mons.begin(), mons.end(), b);
  long long p;
  long long strong_damage = 0LL, weak_damage = 0LL;
  if (k > a) {
    p = ((1LL * k - 1LL * a) * mod_inv(k)) % MOD;
    strong_damage += (p * sum(n - k, n - 1, prefix)) % MOD;
  }
  if (k + 1 > a) {
    p = ((1LL * k + 1LL - 1LL * a) * mod_inv(k + 1LL)) % MOD;
    weak_damage += (p * sum(0, n - k - 1, prefix)) % MOD;
  }
  return (strong_damage + weak_damage) % MOD;
}
vector<int> get_damages(vector<int> &mons, vector<pair<int, int>> &shields,
                        int n, int m) {
  vector<int> ans;
  vector<long long> prefix(n + 3, 0LL);
  sort(mons.begin(), mons.end());
  prefix[0] = mons[0];
  for (int i = 1; i < n; i++) {
    prefix[i] = (prefix[i - 1] + (long long)mons[i]) % MOD;
  }
  for (auto &[a, b] : shields) {
    int damage = get_damage(a, b, mons, n, prefix);
    ans.push_back(damage);
  }
  return ans;
}
int main() {
  io();
  int n, m, x, y, t;
  cin >> n >> m;
  vector<int> mons(n);
  vector<pair<int, int>> shields;
  shields.reserve(m);
  for (int i = 0; i < n; i++) {
    cin >> mons[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    shields.emplace_back(x, y);
  }
  vector<int> answers = get_damages(mons, shields, n, m);
  for (const int &ans : answers) {
    cout << ans << "\n";
  }
  return 0;
}
