using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static long NN => long.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (a, b) = (c[0], c[1]); var x = new long[][] { new long[] { a, b }, new long[] { 1, 0 }, }; var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var n = NN; var f = new long[][] { new long[] { 1 }, new long[] { 1 }}; var g = Matrix.Mul(Matrix.Pow(x, n / 2), f); ans[u] = (n % 2 == 0 ? (g[0][0] + g[1][0]) : (g[0][0] * (a + 1) + g[1][0] * (b + 1))) % 1_000_000_007; } WriteLine(string.Join("\n", ans)); } class Matrix { static int mod = 1_000_000_007; // 行列の累乗 public static long[][] Pow(long[][] m, long k) { var multi = m; var r = new long[m.Length][]; for (var i = 0; i < m.Length; ++i) { r[i] = new long[m.Length]; r[i][i] = 1; } while (k > 0) { if ((k & 1) == 1) r = Mul(r, multi); multi = Mul(multi, multi); k >>= 1; } return r; } // 行列の積 public static long[][] Mul(long[][] x, long[][] y) { var r = new long[x.Length][]; for (var i = 0; i < x.Length; ++i) r[i] = new long[y[0].Length]; for (var i = 0; i < x.Length; ++i) for (var k = 0; k < x[0].Length; ++k) { for (var j = 0; j < y[0].Length; ++j) r[i][j] = (r[i][j] + x[i][k] * y[k][j]) % mod; } return r; } } }