#include <bits/stdc++.h>
using namespace std;
struct stack {
  int st[100010], size;
  stack() { size = 0; }
  bool empty(void) { return (size == 0); }
  void push(int x) {
    size++;
    st[size] = x;
  }
  int pop(void) {
    size--;
    return (st[size + 1]);
  }
} s;
int n, m, cnt;
long long ans = 1, res;
vector<int> ke[100010];
int num[100010], low[100010], pre[100010], a[100010];
void visit(int u) {
  num[u] = low[u] = ++cnt;
  s.push(u);
  for (int i = 0; i < ke[u].size(); i++) {
    int v = ke[u][i];
    if (!pre[v]) {
      if (num[v])
        low[u] = min(low[u], num[v]);
      else {
        visit(v);
        low[u] = min(low[u], low[v]);
      }
    }
  }
  if (low[u] == num[u]) {
    int mn = 2e9, dem = 0;
    while (!s.empty()) {
      int v = s.pop();
      if (mn > a[v]) {
        mn = a[v];
        dem = 1;
      } else if (mn == a[v])
        dem++;
      pre[v] = 1;
      if (v == u) break;
    }
    res += mn;
    ans = (ans * dem) % 1000000007;
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    ke[u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
    if (!num[i]) visit(i);
  cout << res << " " << ans;
  return 0;
}
