#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
vector<long long> g[N + 2], gr[N + 2];
vector<long long> order;
long long vis[N + 2];
void dfs(long long cur) {
  vis[cur] = 1;
  for (auto x : g[cur]) {
    if (!vis[x]) dfs(x);
  }
  order.push_back(cur);
}
vector<long long> component;
void dfs2(long long cur) {
  vis[cur] = 1;
  for (auto x : gr[cur]) {
    if (!vis[x]) dfs2(x);
  }
  component.push_back(cur);
}
int32_t main() {
  long long n;
  cin >> n;
  long long cost[n + 1];
  for (long long i = 1; i <= n; i++) cin >> cost[i];
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
    gr[y].push_back(x);
  }
  memset(vis, 0, sizeof vis);
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, 0, sizeof vis);
  long long minCost = 0, res = 1;
  for (long long i = 0; i < n; i++) {
    long long cur = order[n - 1 - i];
    if (!vis[cur]) {
      dfs2(cur);
      long long mini = 1e12;
      for (auto x : component) {
        mini = min(mini, cost[x]);
      }
      minCost += mini;
      long long cnt = 0;
      for (auto x : component) {
        if (mini == cost[x]) cnt++;
      }
      res = (res * cnt) % 1000000007;
      component.clear();
    }
  }
  cout << minCost << " " << res << endl;
  return 0;
}
