#define endl "\n" #define all(A) A.begin(), A.end() using pII = pair<int, int>; using ll = longlong; using db = double;
constint INF = 0x3f3f3f3f; constint N = 1e3 + 10, M = 1e7 + 10; const ll p = 9999991;
ll qpow(ll x, ll n){ ll res = 1; while (n) { if (n & 1) res = res * x % p; x = x * x % p; n >>= 1; } return res; }
int n, m; ll f[N], fac[N], facinv[N]; ll inv[M];
ll gao(int _n, int x){ if (x <= _n) return f[x]; int t = (_n & 1) ? -1 : 1; ll res = 0, base = 1; for (int i = 0; i <= _n; ++i) { base = base * (x - i) % p; } for (int i = 0; i <= _n; ++i, t *= -1) { res += 1ll * t * f[i] * base % p * facinv[_n - i] % p * facinv[i] % p * inv[x - i] % p; res = (res + p) % p; } return res; }
voidRUN(){ fac[0] = 1ll; for (int i = 1; i < N; ++i) fac[i] = fac[i - 1] * i % p; facinv[N - 1] = qpow(fac[N - 1], p - 2); for (int i = N - 1; i >= 1; --i) facinv[i - 1] = facinv[i] * i % p; inv[1] = 1; for (int i = 2; i < p; ++i) inv[i] = inv[p % i] * (p - p / i) % p; int T; scanf("%d", &T); while (T--) { scanf("%d %d", &n, &m); for (int i = 0; i <= n; ++i) { scanf("%lld", f + i); } f[n + 1] = gao(n, n + 1); for (int i = 1; i <= n + 1; ++i) f[i] = (f[i] + f[i - 1]) % p; int l, r; for (int cas = 1; cas <= m; ++cas) { scanf("%d %d", &l, &r); printf("%lld\n", (gao(n + 1, r) - gao(n + 1, l - 1) + p) % p); } } }