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++; list = new String[(int)Math.pow(3 - identical, k)]; combination(0); System.out.println(count % 1000000007); System.exit(0); } static boolean contains(String a) { for (int i = 0; i < found; i++) { if (list[i].equals(a)) { return true; } } return false; } static int cInString(String a, char c) { int num = 0; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) == c) { num++; } } return num; } static void comb(int k, char[] digits) { String str = ""; for (int i = 0; i < digits.length; i++) { for (int j = i; j < k; j++) { str += digits[i]; } } } static void combination(int index) { if (index >= k) { if (!contains(a)) { list[found] = a; count += cInString(a, digits[2]); found++; //System.out.println(a); } a = a.substring(0, a.length() - 1); return; } for (int i = 0; i < digits.length; i++) { a += digits[i]; combination(index + 1); } if (a.length() > 0) a = a.substring(0, a.length() - 1); } }