import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author cteam024 */ public class Barrels { static String a = ""; static String list[]; static int count = 0; static int found = 0; static char[] digits = new char[3]; static int k; public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] input = reader.readLine().split(" "); k = Integer.parseInt(input[2]); digits[0] = input[0].charAt(0); digits[1] = input[1].charAt(0); digits[2] = input[3].charAt(0); int identical = 0; if (digits[0] == digits[1]) identical++; if (digits[1] == digits[2]) identical++; if (digits[0] == digits[2] && identical < 2) identical++; identical = 3 - identical; System.out.println((powerOf(identical, k - 1) * k) % 1000000007); System.exit(0); } static long powerOf(int a, int b) { if (b < 0) return 0; if (b == 0) return 1; long result = a; for (int i = 1; i < b; i++) { result *= a; result = result % 1000000007; } return result; } }