#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; }
inline long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (a > 0 && b > 0) (a > b ? a %= b : b %= a);
  return (a == 0 ? b : a);
}
inline long long power(long long x, long long n, long long m = LLONG_MAX) {
  long long res = 1;
  x = (x % m + m) % m;
  while (n) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return res;
}
vector<long long> adj[100005];
vector<long long> tadj[100005];
bool vis[100005];
stack<long long> s;
vector<vector<long long>> scc;
void dfs(long long source) {
  vis[source] = 1;
  for (auto x : adj[source]) {
    if (vis[x]) continue;
    dfs(x);
  }
  s.push(source);
}
void dfs2(vector<long long>& cc, long long source) {
  vis[source] = 1;
  cc.push_back(source);
  for (auto x : tadj[source]) {
    if (vis[x]) continue;
    dfs2(cc, x);
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> cost;
  cost.push_back(0);
  for (long long i = 0; i < n; i++) {
    long long c;
    cin >> c;
    cost.push_back(c);
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    tadj[v].push_back(u);
  }
  memset(vis, 0, sizeof(vis));
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, 0, sizeof(vis));
  while (!s.empty()) {
    long long node = s.top();
    s.pop();
    if (!vis[node]) {
      vector<long long> cc;
      dfs2(cc, node);
      scc.push_back(cc);
    }
  }
  long long mc = 0;
  long long tot = 1;
  for (auto cc : scc) {
    long long minc = 1000000007;
    long long cnt = 0;
    for (auto x : cc) {
      if (cost[x] < minc) {
        minc = cost[x];
        cnt = 1;
      } else if (cost[x] == minc) {
        cnt++;
      }
    }
    mc += minc;
    tot = (tot * cnt) % 1000000007;
  }
  cout << mc << " " << tot << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long i = 1; i <= t; ++i) {
    solve();
  };
  return 0;
}
