#include <bits/stdc++.h>
using namespace std;
bool vis[100005];
int n, m, p[100005], sz;
long long ans, way = 1;
vector<int> g[100005], rg[100005], res[100005], cnt;
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); ++i) {
    int v = g[u][i];
    if (!vis[v]) {
      dfs(v);
    }
  }
  cnt.push_back(u);
}
void rdfs(int u, int k) {
  res[k].push_back(u);
  vis[u] = 1;
  for (int i = 0; i < rg[u].size(); ++i) {
    int v = rg[u][i];
    if (!vis[v]) {
      rdfs(v, k);
    }
  }
}
void calc() {
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = (int)cnt.size() - 1; i >= 0; i--) {
    if (!vis[cnt[i]]) {
      rdfs(cnt[i], sz++);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    rg[b].push_back(a);
  }
  calc();
  for (int i = 0; i < sz; ++i) {
    vector<int> tmp(res[i].size());
    for (int j = 0; j < res[i].size(); ++j) {
      tmp[j] = p[res[i][j] - 1];
    }
    sort(tmp.begin(), tmp.end());
    ans += tmp[0];
    way *= upper_bound(tmp.begin(), tmp.end(), tmp[0]) - tmp.begin();
    way %= (int)1e9 + 7;
  }
  cout << ans << ' ' << way << endl;
}
