#include <bits/stdc++.h>
using namespace std;
vector<long long> G[100007];
long long ord, low[100007], dis[100007], sid[100007], scc, cnt[100007],
    mn[100007], c[100007];
stack<long long> s;
void tarjan(long long u) {
  s.push(u);
  dis[u] = low[u] = ++ord;
  for (long long i = (0); i < (G[u].size()); i++) {
    long long v = G[u][i];
    if (!dis[v]) {
      tarjan(v);
      low[u] = min(low[v], low[u]);
    } else if (!sid[v]) {
      low[u] = min(dis[v], low[u]);
    }
  }
  if (low[u] == dis[u]) {
    ++scc;
    while (1) {
      long long t = s.top();
      s.pop();
      sid[t] = scc;
      mn[scc] = min(mn[scc], c[t]);
      if (t == u) break;
    }
  }
}
int main() {
  long long n, m;
  scanf("%lld", &n);
  for (long long i = (1); i < (n + 1); i++) {
    scanf("%lld", &c[i]);
  }
  scanf("%lld", &m);
  for (long long i = (0); i < (m); i++) {
    long long a, b;
    scanf("%lld %lld", &a, &b);
    G[a].push_back(b);
  }
  memset(dis, 0, sizeof(dis));
  memset(sid, 0, sizeof(sid));
  memset(cnt, 0, sizeof(cnt));
  for (long long i = (0); i < (100007); i++) mn[i] = 1e18;
  for (long long i = (1); i < (n + 1); i++) {
    if (!dis[i]) tarjan(i);
  }
  for (long long i = (1); i < (n + 1); i++) {
    if (c[i] == mn[sid[i]]) cnt[sid[i]]++;
  }
  long long minc = 0ll, way = 1ll;
  for (long long i = (1); i < (scc + 1); i++) {
    minc += mn[i];
    way = (way * cnt[i]) % 1000000007;
  }
  printf("%lld ", minc);
  printf("%lld\n", way);
}
