public static void main(String[] args){
		
		Scanner in = new Scanner(System.in);
		
		n =in.nextInt();
		cost = new int[n+1];
		visited = new boolean[n+1];
		
		g.add(new ArrayList<Integer>());
		gR.add(new ArrayList<Integer>());
		for(int i=1;i<=n;i++){
			cost[i]=in.nextInt();
			visited[i]=false;
			g.add(new ArrayList<Integer>());
			gR.add(new ArrayList<Integer>());
		}
		
		int m = in.nextInt();
		for(int i=0;i<m;i++){
			int u = in.nextInt();
			int v = in.nextInt();
			g.get(u).add(v);
			gR.get(v).add(u);
		}
		
		for(int i=1;i<=n;i++){
			if(visited[i]==false){
				dfs(i);
			}
		}
		
		removed = new boolean[n+1];
		for(int i=1;i<=n;i++){visited[i]=false; removed[i]=false;}
		
		long result = 1;
		int mod = 1000000007;
		long minSum = 0;
		while(!s.isEmpty()){
			min = Integer.MAX_VALUE;
			minCount = 1;
			int node = s.pop();
			if(removed[node]==true){continue;}
			dfsR(node);
			result = result*minCount%mod;
			minSum+=min;
		}
		
		System.out.println(minSum + " " + result);
	}