#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int MAXN = 0;
vector<long long> adj1[111111], adj2[111111], order, component;
long long cost[111111];
bool visited[111111];
void dfs1(long long v) {
  visited[v] = true;
  for (auto z : adj1[v]) {
    if (!visited[z]) dfs1(z);
  }
  order.push_back(v);
}
void dfs2(long long v) {
  visited[v] = true;
  component.push_back(v);
  for (auto z : adj2[v]) {
    if (!visited[z]) dfs2(z);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> cost[i];
  long long m;
  cin >> m;
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    adj1[x].push_back(y);
    adj2[y].push_back(x);
  }
  memset(visited, false, sizeof(visited));
  for (long long i = 1; i <= n; i++) {
    if (!visited[i]) dfs1(i);
  }
  memset(visited, false, sizeof(visited));
  long long ans1 = 0;
  long long ways = 1;
  for (long long i = 1; i <= n; i++) {
    long long pos = order[n - i];
    if (!visited[pos]) {
      dfs2(pos);
      long long temp1 = INT_MAX;
      for (long long j = 0; j < component.size(); j++) {
        temp1 = min(temp1, cost[component[j]]);
      }
      ans1 += temp1;
      long long temp2 = 0;
      for (long long j = 0; j < component.size(); j++) {
        if (cost[component[j]] == temp1) temp2++;
      }
      ways = (ways * temp2) % 1000000007LL;
    }
    component.clear();
  }
  cout << ans1 << " " << ways << '\n';
}
