#include <bits/stdc++.h>
using namespace std;
int const INF = 0x3fffffff;
int const MOD = 1e9 + 7;
int const maxn = 1e5 + 5;
int n, m, dfn[maxn], low[maxn], vis[maxn], num;
int a[maxn];
vector<int> E[maxn];
stack<int> s;
long long ans, tot;
void tarjan(int x) {
  dfn[x] = low[x] = ++num;
  s.push(x);
  vis[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (!dfn[v]) {
      tarjan(v);
      low[x] = min(low[x], low[v]);
    } else if (vis[v]) {
      low[x] = min(low[x], dfn[v]);
    }
  }
  if (dfn[x] == low[x]) {
    int cnt = 0, minn = INF, u;
    do {
      u = s.top();
      s.pop();
      vis[u] = 0;
      if (a[u] < minn) {
        minn = a[u];
        cnt = 0;
      }
      if (a[u] == minn) {
        cnt++;
      }
    } while (u != x);
    ans += minn;
    tot = ((tot % MOD) * (cnt % MOD)) % MOD;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &m);
  while (m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    E[x].push_back(y);
  }
  tot = 1;
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  printf("%lld %lld\n", ans, tot);
  return 0;
}
