import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class WrapAround3 {

    int N = 41;

    int n, m;
    char[] s;

    int[] f;
    List<Integer>[][] prev = new List[N][2];
    int[][] next = new int[N][2];

    long[][] dp = new long[N][N];
    long[][] ep = new long[N][N];

    void solve() {
        n = in.nextInt();
        s = in.nextToken().toCharArray();
        m = s.length;

        f = fail(s);

        for (int i = 0; i < N; i++) for (int j = 0; j < 2; j++) prev[i][j] = new ArrayList<>();
        for (int i = 0; i <= m; i++) {
            for (int x = 0; x <= 1; x++) {
                int j = getNext(i, (char) (x + '0'));
                prev[j][x].add(i);
                next[i][x] = j;
            }
        }

        long ans = 0;
        for (int i = 0; i < N; i++) Arrays.fill(dp[i], -1);
        for (int i = 0; i < N; i++) Arrays.fill(ep[i], -1);
        for (int i = 0; i <= m; i++) {
            for (int pos = 0; pos < n; pos++) {
                ans += f(pos + 1, i) * g(n - pos - 1, i);
            }
        }
        out.println(ans);
    }

    long f(int n, int cur) {
        if (n == 0) return cur == m ? 1 : 0;
        if (dp[n][cur] >= 0) return dp[n][cur];
        long res = 0;
        for (int i = 0; i <= 1; i++) {
            int nxt = next[cur][i];
            if (n - 1 > 0 && nxt == m) continue;
            res += f(n - 1, nxt);
        }
        return dp[n][cur] = res;
    }

    long g(int n, int cur) {
        if (n == 0) return cur == m ? 1 : 0;
        if (ep[n][cur] >= 0) return ep[n][cur];
        long res = 0;
        for (int i = 0; i <= 1; i++) {
            for (int nxt : prev[cur][i]) {
                res += g(n - 1, nxt);
            }
        }
        return ep[n][cur] = res;
    }

    int getNext(int now, char x) {
        if (now == m) now = f[now];
        while (now > 0 && s[now] != x) now = f[now];
        return s[now] == x ? now + 1 : 0;
    }

    int[] fail(char[] s) {
        int n = s.length;
        int[] f = new int[n + 1];
        f[0] = f[1] = 0;
        for (int i = 2; i <= n; i++) {
            int j = f[i - 1];
            while (j > 0 && s[j] != s[i - 1]) j = f[j];
            f[i] = s[j] == s[i - 1] ? j + 1 : 0;
        }
        return f;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new WrapAround3().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


//package educational.round07;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class FX {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	int mod = 1000000007;

	void solve()
	{
		int n = ni(), K = ni();
		long[] vals = new long[K+3];
		for(int i = 1;i <= K+2;i++){
			vals[i] = pow(i, K, mod);
		}
		if(n <= K+2){
			long s = 0;
			for(int i = 1;i <= n;i++){
				s += vals[i];
			}
			out.println(s%mod);
		}else{
			for(int i = 2;i <= K+2;i++){
				vals[i] += vals[i-1];
				if(vals[i] >= mod)vals[i] -= mod;
			}
			int[][] fif = enumFIF(K+3, mod);
			long mul = 1;
			for(int i = 1;i <= K+2;i++){
				mul = mul * (n-i)%mod;
			}
			long s = 0;
			long sig = 1;
			long big = 8L*mod*mod;
			for(int i = K+2;i >= 1;i--){
				s += invl(n-i, mod) * fif[1][i-1] % mod * fif[1][K+2-i] % mod * vals[i] * sig;
				if(s >= big)s -= big;
				if(s <= -big)s += big;
				sig = -sig;
			}
			s %= mod;
			if(s < 0)s += mod;
			s = s * mul % mod;
			out.println(s);
		}
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	public static long invl(long a, long mod) {
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		return p < 0 ? p + mod : p;
	}

	public static int[][] enumFIF(int n, int mod) {
		int[] f = new int[n + 1];
		int[] invf = new int[n + 1];
		f[0] = 1;
		for (int i = 1; i <= n; i++) {
			f[i] = (int) ((long) f[i - 1] * i % mod);
		}
		long a = f[n];
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		invf[n] = (int) (p < 0 ? p + mod : p);
		for (int i = n - 1; i >= 0; i--) {
			invf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);
		}
		return new int[][] { f, invf };
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new FX().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.util.*;

public class D {

    public void solve() {
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            String s = in.nextToken().substring(4);
            out.println(getAns(s));
        }
    }

    private long getAns(String s) {
        long cur = 1988;
        for (int j = s.length() - 1; j >= 0; j--) {
            long last = 0, pow = 1;
            for (int t = j; t < s.length(); t++) {
                last = last * 10 + s.charAt(t) - '0';
                pow *= 10;
            }

            if (cur % pow < last) {
                cur = (cur / pow) * pow + last;
            } else {
                cur = (cur / pow + 1) * pow + last;
            }
        }
        return cur;
    }

    public void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    FastScanner in;
    PrintWriter out;

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        new D().run();
    }
}


import java.io.*;
import java.util.*;

public class Codeforces979E {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int p = Integer.parseInt(st.nextToken());
		int[] c = new int[n];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < n; i++) {
			c[i] = Integer.parseInt(st.nextToken());
		}

		//list of powers of 2 until 2^{n^2}, mod 1000000007
		int[] twopower = new int[n*n+1];
		twopower[0] = 1;
		for (int i = 1; i <= n*n; i++) {
			twopower[i] = (2*twopower[i-1])%1000000007;
		}

		//Pascal's triangle until n choose k, mod 1000000007
		int[][] pascal = new int[n+1][n+1];
		for (int i = 0; i <= n; i++) {
			pascal[i][0] = 1;
			pascal[0][i] = 1;
		}
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				pascal[i][j] = (pascal[i][j-1]+pascal[i-1][j])%1000000007;
			}
		}

		//dp[x][y][z] means the last x have all arrows intact
		//and there are y 0's and z 1's at the start with no
		//arrows going between them.
		//we only care when 0 <= x+y+z <= n.
		//answer is dp[n][0][0].
		int[][][] dp = new int[n+1][n+1][n+1];
		//base case of x = 0
		for (int y = 0; y <= n; y++) {
			for (int z = 0; z <= (n-y); z++) {
				if (p == (y+z)%2) {
					dp[0][y][z] = 1;
				}
			}
		}

		for (int x = 1; x <= n; x++) {
			for (int y = 0; y <= (n-x); y++) {
				for (int z = 0; z <= (n-x-y); z++) {
					if (c[n-x] != 1) {
						int evenmultiple;
						int oddmultiple;
						if (z == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[z-1];
							oddmultiple = twopower[z-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y+1][z];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[y];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					if (c[n-x] != 0) {
						int evenmultiple;
						int oddmultiple;
						if (y == 0) {
							evenmultiple = 1;
							oddmultiple = 0;
						}
						else {
							evenmultiple = twopower[y-1];
							oddmultiple = twopower[y-1];
						}
						long evenk = (long) evenmultiple * (long) dp[x-1][y][z+1];
						evenk %= 1000000007;
						long oddk = (long) oddmultiple * (long) dp[x-1][y][z];
						oddk %= 1000000007;
						oddk *= (long) twopower[x-1];
						oddk %= 1000000007;
						long totalk = evenk+oddk;
						totalk *= twopower[z];
						totalk %= 1000000007;
						dp[x][y][z] += (int) totalk;
					}
					dp[x][y][z] %= 1000000007;
				}
			}
		}

		pw.println(dp[n][0][0]);

		pw.close();
	}
}


/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

import java.io.*;
import java.math.*;
import java.util.*;

public class Codeforces429D
{

	InputStream in;
	PrintWriter out;

	long MAX=Long.MAX_VALUE;
	void solve()
	{
		long f=nl();
		long T=nl();
		long t0=nl();
		long a1,t1,p1,a2,t2,p2;
		a1=nl();t1=nl();p1=nl();
		a2=nl();t2=nl();p2=nl();

		long max1=f/a1;
		long max2=f/a2;
		long cost=MAX;

		if (t1<t2)
		{
			for (int k1=0;k1<=max1;k1++)
			{
				long sz=f-k1*a1;

				long l=0,r=sz/a2,result=-1,t=a1*k1*t1;
				long td;
				while (l<=r)
				{
					long mid=((l+r)>>1);
					td=a2*mid;
					if (t+td*t2+(sz-td)*t0 <= T)
					{
						result=mid;
						r=mid-1;
					}
					else
					{
						l=mid+1;
					}
				}

				if (t+sz*t2<=T)
					cost=Math.min(cost, k1*p1+((sz+a2-1)/a2)*p2);

				if (result!=-1)
				{
					cost=Math.min(cost, k1*p1+result*p2);
				}

			}

			if (f*t1<=T)
				cost=Math.min(cost, ((f+a1-1)/a1)*p1);
		}
		else
		{
			for (int k2=0;k2<=max2;k2++)
			{
				long sz=f-k2*a2;

				long l=0,r=sz/a1,result=-1,t=a2*k2*t2;
				long td;
				while (l<=r)
				{
					long mid=((l+r)>>1);
					td=a1*mid;
					if (t+td*t1+(sz-td)*t0<=T)
					{
						result=mid;
						r=mid-1;
					}
					else
					{
						l=mid+1;
					}
				}

				if (t+sz*t1<=T)
					cost=Math.min(cost, k2*p2+((sz+a1-1)/a1)*p1);

				if (result!=-1)
				{
					cost=Math.min(cost, k2*p2+result*p1);
				}

			}

			if (f*t2<=T)
				cost=Math.min(cost, ((f+a2-1)/a2)*p2);
		}

		if (cost==MAX)
			out.println(-1);
		else
			out.println(cost);
	}

	void run() throws Exception
	{
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		out = new PrintWriter(System.out);
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis() - s + "ms");

	}
	public static void main(String[] args) throws Exception
	{
		new Codeforces429D().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf)
		{
			ptrbuf = 0;
			try
			{
				lenbuf = in.read(inbuf);
			}
			catch (IOException e)
			{
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean inSpaceChar(int c)
	{
		return !(c >= 33 && c <= 126);
	}

	private int skip()
	{
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(b))
			;
		return b;
	}

	private double nd()
	{
		return Double.parseDouble(ns());
	}

	private char nc()
	{
		return (char) skip();
	}

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(inSpaceChar(b)))
		{ // when nextLine, (inSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(inSpaceChar(b)))
		{
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-')
		{
			minus = true;
			b = readByte();
		}

		while (true)
		{
			if (b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}
			else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-')
		{
			minus = true;
			b = readByte();
		}

		while (true)
		{
			if (b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}
			else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o)
	{
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

}


import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author AlexFetisov
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskE solver = new TaskE();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskE {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int x = in.nextInt();
        int n = in.nextInt();
        int pi = in.nextInt();
        double p = (1. * pi) / 100.;
        double[][][][] dp = new double[2][256][2][n + 32];
        ArrayUtils.fill(dp, 0);
        if (x / 256 % 2 == 0) {
            dp[0][x % 256][0][x < 256 ? 0 : Integer.numberOfTrailingZeros(x / 256)] = 1.0;
        } else {
            dp[0][x % 256][1][Integer.numberOfTrailingZeros(x / 256 + 1)] = 1.0;
        }
        for (int i = 0; i < n; ++i) {
            ArrayUtils.fill(dp[1], 0);
            for (int high = 0; high < n + 31; ++high) {
                for (int low = 0; low < 256; ++low) {
                    double notP = (1.0 - p);
                    {
                        if (low < 128) {
                            dp[1][low * 2][0][high == 0 ? 0 : high + 1] += dp[0][low][0][high] * p;
                            dp[1][low * 2][0][1] += dp[0][low][1][high] * p;
                        } else {
                            dp[1][(low * 2) % 256][1][1] += dp[0][low][0][high] * p;
                            dp[1][(low * 2) % 256][1][high + 1] += dp[0][low][1][high] * p;
                        }
                    }
                    {
                        if (low < 255) {
                            dp[1][low + 1][0][high] += dp[0][low][0][high] * notP;
                            dp[1][low + 1][1][high] += dp[0][low][1][high] * notP;
                        } else {
                            dp[1][0][1][1] += dp[0][low][0][high] * notP;
                            dp[1][0][0][high] += dp[0][low][1][high] * notP;
                        }
                    }
                }
            }
            double[][][] temp = dp[0];
            dp[0] = dp[1];
            dp[1] = temp;
        }
        double res = 0;
        for (int high = 0; high < n + 32; ++high) {
            for (int low = 0; low < 256; ++low) {
                res += dp[0][low][0][high] * (low == 0 ? 8 + high : Integer.numberOfTrailingZeros(low));
                res += dp[0][low][1][high] * (low == 0 ? 8 : Integer.numberOfTrailingZeros(low));
            }
        }
        out.printf("%.13f\n", res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

    public String nextLine() {
        try {
            return reader.readLine().trim();
        } catch (IOException e) {
            return null;
        }
    }

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(nextString());
    }

}

class ArrayUtils {

    public static void fill(double[][][] f, double value) {
        for (int i = 0; i < f.length; ++i) {
            for (int j = 0; j < f[i].length; ++j) {
                Arrays.fill(f[i][j], value);
            }
        }
    }

    public static void fill(double[][][][] g, int value) {
        for (int i = 0; i < g.length; ++i) {
            ArrayUtils.fill(g[i], value);
        }
    }

}


//package com.example.practice.codeforces.sc2900.prac;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

//G. Long Binary String
public class Solution1 {
    // https://abcdxyzk.github.io/blog/2018/04/16/isal-erase-3/
    // https://zhuanlan.zhihu.com/p/132603308
    public static void main (String [] args) throws IOException {
        // Use BufferedReader rather than RandomAccessFile; it's much faster
        final BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        // input file name goes above
        //StringTokenizer st = new StringTokenizer(input.readLine());
        //int n = Integer.parseInt(st.nextToken()), a = Integer.parseInt(st.nextToken()), b = Integer.parseInt(st.nextToken()), k = Integer.parseInt(st.nextToken());
        long[] res = calc(input.readLine());
        if (res==null){
            out.println(-1);
        }else {
            printArray(res, out);
        }
        out.close();       // close the output file
    }

    private static long[] calc(final String s) {
        long px = 0, v = 1;
        int p = s.length()-1, tem = 0, highest = 0, first = 0, c = 0;
        while (p>=0 && s.charAt(p)=='0'){
            p--;
        }
        if (p<0)return null;
        while (p>=0){
            if (s.charAt(p)=='1'){
                px |= 1L << tem;
                highest = tem;
                first = p;
                c++;
            }
            tem++;
            p--;
        }
        if (c==1)return new long[]{first+1, first+2};
        final long m = (long) Math.sqrt(1L<<highest) + 1;
        HashMap<Long, Long> map = new HashMap<>();
        for (int i=1;i<=m;++i){
            v = v << 1;
            if ((v & (1L<<highest)) != 0){
                v = v ^ px;
            }
            if (v == 1){
                return new long[]{first+1, first+1+i};
            }
            if (i<m){
                map.put(v, (long)i);
            }
        }
        final long d = v;
        for (int i=2;i<=m;++i){
            v = multi(px, v, d, highest);
            if (v==1){
                return new long[]{first + 1, first + 1 + m * i};
            }
            Long j = map.get(v);
            if (j != null){
                return new long[]{first + 1, first + 1 + m * i - j};
            }
        }
        return null;
    }

    private static long multi(final long px, final long v, final long d, final int highest){
        long res = 0;
        for (int i=0;i<highest;++i){
            if ((d & (1L<<i)) != 0) {
                int t = i;
                long v2 = v;
                while (t > 0) {
                    v2 = v2 << 1;
                    if ((v2 & (1L<<highest)) != 0){
                        v2 = v2 ^ px;
                    }
                    t--;
                }
                res = res ^ v2;
            }
        }
        return res;
    }

    private static void printArray(long[] ns, final PrintWriter out){
        for (int i=0;i<ns.length;++i){
            out.print(ns[i]);
            if (i+1<ns.length)out.print(" ");
            else out.println();
        }
    }

    private static void printArrayInt(int[] ns, final PrintWriter out){
        for (int i=0;i<ns.length;++i){
            out.print(ns[i]);
            if (i+1<ns.length)out.print(" ");
            else out.println();
        }
    }

    private static void printArrayVertical(long[] ns, final PrintWriter out){
        for (long a : ns){
            out.println(a);
        }
    }

    private static void printArray2D(long[][] ns, final int len, final PrintWriter out){
        int cnt = 0;
        for (long[] kk : ns){
            cnt++;
            if (cnt > len)break;
            for (int i=0;i<kk.length;++i){
                out.print(kk[i]);
                if (i+1<kk.length)out.print(" ");
                else out.println();
            }
        }
    }

    private static void printArray2DInt(int[][] ns, final int len, final PrintWriter out){
        int cnt = 0;
        for (int[] kk : ns){
            cnt++;
            if (cnt > len)break;
            for (int i=0;i<kk.length;++i){
                out.print(kk[i]);
                if (i+1<kk.length)out.print(" ");
                else out.println();
            }
        }
    }

    private static long[] readArray(final int n, final BufferedReader input) throws IOException{
        long[] ns = new long[n];
        StringTokenizer st = new StringTokenizer(input.readLine());
        for (int i=0;i<n;++i){
            ns[i] = Long.parseLong(st.nextToken());
        }
        return ns;
    }

    private static int[] readArrayInt(final int n, final BufferedReader input) throws IOException{
        int[] ns = new int[n];
        StringTokenizer st = new StringTokenizer(input.readLine());
        for (int i=0;i<n;++i){
            ns[i] = Integer.parseInt(st.nextToken());
        }
        return ns;
    }

    private static long[] readArrayVertical(final int n, final BufferedReader input) throws IOException{
        long[] ns = new long[n];
        for (int i=0;i<n;++i){
            ns[i] = Long.parseLong(input.readLine());
        }
        return ns;
    }

    private static long[][] readArray2D(final int n, final int len, final BufferedReader input) throws IOException{
        long[][] ns = new long[len][];
        for (int i=0;i<n;++i){
            StringTokenizer st = new StringTokenizer(input.readLine());
            ArrayList<Long> al = new ArrayList<>();
            while (st.hasMoreTokens()){
                al.add(Long.parseLong(st.nextToken()));
            }
            long[] kk = new long[al.size()];
            for (int j=0;j<kk.length;++j){
                kk[j] = al.get(j);
            }
            ns[i] = kk;
        }
        return ns;
    }

    private static int[][] readArray2DInt(final int n, final int len, final BufferedReader input) throws IOException{
        int[][] ns = new int[len][];
        for (int i=0;i<n;++i){
            StringTokenizer st = new StringTokenizer(input.readLine());
            ArrayList<Integer> al = new ArrayList<>();
            while (st.hasMoreTokens()){
                al.add(Integer.parseInt(st.nextToken()));
            }
            int[] kk = new int[al.size()];
            for (int j=0;j<kk.length;++j){
                kk[j] = al.get(j);
            }
            ns[i] = kk;
        }
        return ns;
    }

    static class SegTree{
        int st;
        int en;
        int mid;
        int val1;
        int val2;
        SegTree left;
        SegTree right;
        public SegTree(int l, int r, int d){
            st = l;
            en = r;
            mid = (st + en) >> 1;
            val1 = val2 = d;
            if (st<en){
                left = new SegTree(st, mid, d);
                right = new SegTree(mid+1, en, d);
            }else {
                left = right = null;
            }
        }

        public SegTree(int l, int r, int[] ns){
            st = l;
            en = r;
            mid = (st + en) >> 1;
            if (st==en){
                val1 = val2 = ns[st];
            }else {
                left = new SegTree(l, mid, ns);
                right = new SegTree(mid+1, r, ns);
                val1 = Math.min(left.val1, right.val1);
                val2 = Math.max(left.val2, right.val2);
            }
        }

        void update(int idx, int v){
            if (st==en){
                val1 = val2 = v;
            }else {
                if (idx <= mid){
                    left.update(idx, v);
                }else {
                    right.update(idx, v);
                }
                val1 = Math.min(left.val1, right.val1);
                val2 = Math.max(left.val2, right.val2);
            }
        }

        int getMin(int l, int r){
            if (st==en || (l==st && r==en))return val1;
            if (r<=mid){
                return left.getMin(l, r);
            }
            if (l>mid){
                return right.getMin(l, r);
            }
            return Math.min(left.getMin(l, mid), right.getMin(mid+1, r));
        }

        int getMax(int l, int r){
            if (st==en || (l==st && r==en))return val2;
            if (r<=mid){
                return left.getMax(l, r);
            }
            if (l>mid){
                return right.getMax(l, r);
            }
            return Math.max(left.getMax(l, mid), right.getMax(mid+1, r));
        }
    }

    static class SparseTable{
        int[][] minTable;
        int[][] maxTable;
        int[] log2;
        int n;
        public SparseTable(final int[] ns){
            n = ns.length;
            int m = 0, pre = 0;
            while (1<<m < n){
                m++;
            }
            m++;
            minTable = new int[n][m];
            maxTable = new int[n][m];
            log2 = new int[n+1];
            for (int i=0;i<n;++i){
                minTable[i][0] = ns[i];
                maxTable[i][0] = ns[i];
                if ((1<<(pre+1)) == i+1){
                    pre++;
                }
                log2[i+1] = pre;
            }
            for (int i=1;i<m;++i){
                for (int j=0;j<n;++j){
                    int r = Math.min(n-1, j+(1<<i)-1);
                    if (r-(1<<(i-1))+1 <= j){
                        minTable[j][i] = minTable[j][i-1];
                        maxTable[j][i] = maxTable[j][i-1];
                    }else {
                        minTable[j][i] = Math.min(minTable[j][i-1], minTable[r-(1<<(i-1))+1][i-1]);
                        maxTable[j][i] = Math.max(maxTable[j][i-1], maxTable[r-(1<<(i-1))+1][i-1]);
                    }
                }
            }
        }

        int getMin(final int l, final int r){
            int d = log2[r-l+1];
            return Math.min(minTable[l][d], minTable[r-(1<<d)+1][d]);
        }

        int getMax(final int l, final int r){
            int d = log2[r-l+1];
            return Math.max(maxTable[l][d], maxTable[r-(1<<d)+1][d]);
        }
    }
}


//package ecr107;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;

public class F2 {
	InputStream is;
	FastWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), m = ni();
		char[][] ss = new char[n][];
		String[] oss = new String[n];
		for(int i = 0;i < n;i++){
			ss[i] = ns().toCharArray();
			oss[i] = new String(ss[i]);
		}
		int[] offset = new int[n+1];
		offset[0] = 1;
		for(int i = 0;i < n;i++){
			offset[i+1] = offset[i] + ss[i].length-1;
		}
		int U = offset[n]-1;

		final int D = 5;
		int[][] M = new int[(U+1)*D][(U+1)*D];
//		tr(offset);
		for(int i = 0;i < U+1;i++){
			int lb, of;
			if(i == 0) {
				lb = 0;
				of = 0;
			}else{
				lb = lowerBound(offset, i+1) - 1;
				of = i-offset[lb] + 1;
			}
//			tr(i, lb, of, U);

			if(i == 0){
				for(int j = 0;j < n;j++){
					for(int k = 0;k < n;k++){
						if(k != j && oss[k].startsWith(oss[j])){
							M[offset[k]+ss[j].length-1][0+(U+1)*(ss[j].length-1)] = 1;
						}
					}
					M[0][0+(U+1)*(ss[j].length-1)] += 1;
				}
			}else{
				// r: 0 -> 0
				for(int j = 0;j < n;j++){
					if(oss[lb].substring(of).equals(oss[j])){
						M[0][i+(U+1)*(oss[j].length()-1)] += 2;
					}else if(oss[lb].substring(of).startsWith(oss[j])){
						M[i+oss[j].length()][i+(U+1)*(oss[j].length()-1)] += 1;
					}
				}
				// l: -> 0
				String suf = oss[lb].substring(of);
				for(int j = 0;j < n;j++){
					if(oss[j].startsWith(suf) && !oss[j].equals(suf)){
						M[offset[j]+suf.length()-1][i+(U+1)*(suf.length()-1)] += 1;
					}
				}
			}
		}
		for(int i = 0;i < U+1;i++){
			for(int j = 0;j < D-1;j++){
				M[i+(U+1)*(j+1)][i+(U+1)*j] = 1;
			}
		}

//		for(int[] row : M){
//			tr(row);
//		}

		int[] v = new int[(U+1)*D];
		v[0] = 1;
		v = pow(M, v, m);
//		for(int i = 1;i < U+1;i++){
//			if(v[i] != v[i+U]){
//				tr("diff", i, i+U, v[i], v[i+U]);
//			}
//		}
//		tr(v);
		out.println(v[0]);
	}

	///////// begin
	public static final int mod = 998244353;
	public static final long m2 = (long)mod*mod;
	public static final long BIG = 8L*m2;

	// A^e*v
	public static int[] pow(int[][] A, int[] v, long e)
	{
		for(int i = 0;i < v.length;i++){
			if(v[i] >= mod)v[i] %= mod;
		}
		int[][] MUL = A;
		for(;e > 0;e>>>=1) {
			if((e&1)==1)v = mul(MUL, v);
			MUL = p2(MUL);
		}
		return v;
	}

	// int matrix*int vector
	public static int[] mul(int[][] A, int[] v)
	{
		int m = A.length;
		int n = v.length;
		int[] w = new int[m];
		for(int i = 0;i < m;i++){
			long sum = 0;
			for(int k = 0;k < n;k++){
				sum += (long)A[i][k] * v[k];
				if(sum >= BIG)sum -= BIG;
			}
			w[i] = (int)(sum % mod);
		}
		return w;
	}

	// int matrix^2 (be careful about negative value)
	public static int[][] p2(int[][] A)
	{
		int n = A.length;
		int[][] C = new int[n][n];
		for(int i = 0;i < n;i++){
			long[] sum = new long[n];
			for(int k = 0;k < n;k++){
				for(int j = 0;j < n;j++){
					sum[j] += (long)A[i][k] * A[k][j];
					if(sum[j] >= BIG)sum[j] -= BIG;
				}
			}
			for(int j = 0;j < n;j++){
				C[i][j] = (int)(sum[j] % mod);
			}
		}
		return C;
	}

	public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
	public static int lowerBound(int[] a, int l, int r, int v)
	{
		if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
		int low = l-1, high = r;
		while(high-low > 1){
			int h = high+low>>>1;
			if(a[h] >= v){
				high = h;
			}else{
				low = h;
			}
		}
		return high;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new FastWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F2().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}

	private int ni() { return (int)nl(); }

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	public static class FastWriter
	{
		private static final int BUF_SIZE = 1<<13;
		private final byte[] buf = new byte[BUF_SIZE];
		private final OutputStream out;
		private int ptr = 0;

		private FastWriter(){out = null;}

		public FastWriter(OutputStream os)
		{
			this.out = os;
		}

		public FastWriter(String path)
		{
			try {
				this.out = new FileOutputStream(path);
			} catch (FileNotFoundException e) {
				throw new RuntimeException("FastWriter");
			}
		}

		public FastWriter write(byte b)
		{
			buf[ptr++] = b;
			if(ptr == BUF_SIZE)innerflush();
			return this;
		}

		public FastWriter write(char c)
		{
			return write((byte)c);
		}

		public FastWriter write(char[] s)
		{
			for(char c : s){
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			}
			return this;
		}

		public FastWriter write(String s)
		{
			s.chars().forEach(c -> {
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			});
			return this;
		}

		private static int countDigits(int l) {
			if (l >= 1000000000) return 10;
			if (l >= 100000000) return 9;
			if (l >= 10000000) return 8;
			if (l >= 1000000) return 7;
			if (l >= 100000) return 6;
			if (l >= 10000) return 5;
			if (l >= 1000) return 4;
			if (l >= 100) return 3;
			if (l >= 10) return 2;
			return 1;
		}

		public FastWriter write(int x)
		{
			if(x == Integer.MIN_VALUE){
				return write((long)x);
			}
			if(ptr + 12 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		private static int countDigits(long l) {
			if (l >= 1000000000000000000L) return 19;
			if (l >= 100000000000000000L) return 18;
			if (l >= 10000000000000000L) return 17;
			if (l >= 1000000000000000L) return 16;
			if (l >= 100000000000000L) return 15;
			if (l >= 10000000000000L) return 14;
			if (l >= 1000000000000L) return 13;
			if (l >= 100000000000L) return 12;
			if (l >= 10000000000L) return 11;
			if (l >= 1000000000L) return 10;
			if (l >= 100000000L) return 9;
			if (l >= 10000000L) return 8;
			if (l >= 1000000L) return 7;
			if (l >= 100000L) return 6;
			if (l >= 10000L) return 5;
			if (l >= 1000L) return 4;
			if (l >= 100L) return 3;
			if (l >= 10L) return 2;
			return 1;
		}

		public FastWriter write(long x)
		{
			if(x == Long.MIN_VALUE){
				return write("" + x);
			}
			if(ptr + 21 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		public FastWriter write(double x, int precision)
		{
			if(x < 0){
				write('-');
				x = -x;
			}
			x += Math.pow(10, -precision)/2;
			//		if(x < 0){ x = 0; }
			write((long)x).write(".");
			x -= (long)x;
			for(int i = 0;i < precision;i++){
				x *= 10;
				write((char)('0'+(int)x));
				x -= (int)x;
			}
			return this;
		}

		public FastWriter writeln(char c){
			return write(c).writeln();
		}

		public FastWriter writeln(int x){
			return write(x).writeln();
		}

		public FastWriter writeln(long x){
			return write(x).writeln();
		}

		public FastWriter writeln(double x, int precision){
			return write(x, precision).writeln();
		}

		public FastWriter write(int... xs)
		{
			boolean first = true;
			for(int x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter write(long... xs)
		{
			boolean first = true;
			for(long x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter writeln()
		{
			return write((byte)'\n');
		}

		public FastWriter writeln(int... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(long... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(char[] line)
		{
			return write(line).writeln();
		}

		public FastWriter writeln(char[]... map)
		{
			for(char[] line : map)write(line).writeln();
			return this;
		}

		public FastWriter writeln(String s)
		{
			return write(s).writeln();
		}

		private void innerflush()
		{
			try {
				out.write(buf, 0, ptr);
				ptr = 0;
			} catch (IOException e) {
				throw new RuntimeException("innerflush");
			}
		}

		public void flush()
		{
			innerflush();
			try {
				out.flush();
			} catch (IOException e) {
				throw new RuntimeException("flush");
			}
		}

		public FastWriter print(byte b) { return write(b); }
		public FastWriter print(char c) { return write(c); }
		public FastWriter print(char[] s) { return write(s); }
		public FastWriter print(String s) { return write(s); }
		public FastWriter print(int x) { return write(x); }
		public FastWriter print(long x) { return write(x); }
		public FastWriter print(double x, int precision) { return write(x, precision); }
		public FastWriter println(char c){ return writeln(c); }
		public FastWriter println(int x){ return writeln(x); }
		public FastWriter println(long x){ return writeln(x); }
		public FastWriter println(double x, int precision){ return writeln(x, precision); }
		public FastWriter print(int... xs) { return write(xs); }
		public FastWriter print(long... xs) { return write(xs); }
		public FastWriter println(int... xs) { return writeln(xs); }
		public FastWriter println(long... xs) { return writeln(xs); }
		public FastWriter println(char[] line) { return writeln(line); }
		public FastWriter println(char[]... map) { return writeln(map); }
		public FastWriter println(String s) { return writeln(s); }
		public FastWriter println() { return writeln(); }
	}

	public void trnz(int... o)
	{
		for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
		System.out.println();
	}

	// print ids which are 1
	public void trt(long... o)
	{
		Queue<Integer> stands = new ArrayDeque<>();
		for(int i = 0;i < o.length;i++){
			for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
		}
		System.out.println(stands);
	}

	public void tf(boolean... r)
	{
		for(boolean x : r)System.out.print(x?'#':'.');
		System.out.println();
	}

	public void tf(boolean[]... b)
	{
		for(boolean[] r : b) {
			for(boolean x : r)System.out.print(x?'#':'.');
			System.out.println();
		}
		System.out.println();
	}

	public void tf(long[]... b)
	{
		if(INPUT.length() != 0) {
			for (long[] r : b) {
				for (long x : r) {
					for (int i = 0; i < 64; i++) {
						System.out.print(x << ~i < 0 ? '#' : '.');
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

	public void tf(long... b)
	{
		if(INPUT.length() != 0) {
			for (long x : b) {
				for (int i = 0; i < 64; i++) {
					System.out.print(x << ~i < 0 ? '#' : '.');
				}
			}
			System.out.println();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.util.*;

public class Codeforces1174E {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int mod = 1000000007;

		int nFact = 1;
		for (int i = 2; i <= n; i++) {
			nFact = multiply(nFact, i, mod);
		}

		int ntemp = n;
		int k = 0;
		while (ntemp > 0) {
			ntemp /= 2;
			k++;
		}

		int[] val = new int[k];
		for (int i = 0; i < k; i++) {
			val[i] = 1 << (k-1-i);
		}
		int[] a = new int[k];
		for (int i = 0; i < k; i++) {
			a[i] = n/(val[i]);
		}
		for (int i = k-1; i > 0; i--) {
			a[i] -= a[i-1];
		}

		int ans = nFact;
		int partialSum = 0;
		for (int i = k-1; i >= 0; i--) {
			partialSum += a[i];
			ans = multiply(ans, multiply(a[i], inverse(partialSum, mod), mod), mod);
		}

		if (n >= (3*val[0])/2) {
			for (int rep = 0; rep < (k-1); rep++) {
				val[rep] = (3*val[rep])/2;

				for (int i = 0; i < k; i++) {
					a[i] = n/(val[i]);
				}
				for (int i = k-1; i > 0; i--) {
					a[i] -= a[i-1];
				}

				int ans2 = nFact;
				partialSum = 0;
				for (int i = k-1; i >= 0; i--) {
					partialSum += a[i];
					ans2 = multiply(ans2, multiply(a[i], inverse(partialSum, mod), mod), mod);
				}

				ans = (ans+ans2)%mod;
			}
		}

		System.out.println(ans);
	}

	public static int multiply (int a, int b, int n) {
		long ab = (long) a * (long) b;
		return ((int) (ab%n));
	}

	public static int inverse (int a, int n) {
		int m = n;
		int r1 = 1;
		int r2 = 0;
		int r3 = 0;
		int r4 = 1;
		while ((a > 0) && (n > 0)) {
			if (n >= a) {
				r3 -= r1*(n/a);
				r4 -= r2*(n/a);
				n = n%a;
			}
			else {
				int tmp = a;
				a = n;
				n = tmp;
				tmp = r1;
				r1 = r3;
				r3 = tmp;
				tmp = r2;
				r2 = r4;
				r4 = tmp;
			}
		}
		if (a == 0) {
			if (r3 >= 0)
				return (r3%m);
			else
				return (m+(r3%m));
		}
		else {
			if (r1 >= 0)
				return (r1%m);
			else
				return (m+(r1%m));
		}

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class PuttingBoxesTogether {

    int N = (int) 2e5 + 10;
    int MOD = (int) 1e9 + 7;

    int n;
    long[] t1 = new long[N];
    long[] t2 = new long[N];

    void solve() {
        n = in.nextInt(); int Q = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = in.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) w[i] = in.nextInt();

        for (int i = 0; i < n; i++) a[i] -= i;

        for (int i = 0; i < n; i++) {
            add(t1, i, w[i]);
            add(t2, i, (long) a[i] * w[i] % MOD);
        }

        while (Q-- > 0) {
            int x = in.nextInt();
            if (x < 0) {
                int i = -x - 1, nw = in.nextInt();
                long delta1 = nw - w[i];
                long delta2 = mul(a[i], nw) - mul(a[i], w[i]);
                w[i] = nw;
                add(t1, i, delta1);
                add(t2, i, delta2);
            } else {
                int l = x - 1, r = in.nextInt();
                long tot = sum(t1, l, r);
                int lb = l, ub = r;
                while (ub - lb > 1) {
                    int m = (lb + ub) >> 1;
                    if (sum(t1, l, m) * 2 <= tot) lb = m;
                    else ub = m;
                }
                int k = lb;
                long ans = norm(mul(a[k], nsum(t1, l, k)) - nsum(t2, l, k));
                ans = norm(ans + norm(nsum(t2, k + 1, r) - mul(a[k], nsum(t1, k + 1, r))));
                out.println(ans);
            }
        }
    }

    long nsum(long[] t, int l, int r) {
        return norm(sum(t, r - 1) - sum(t, l - 1));
    }

    long sum(long[] t, int l, int r) {
        return sum(t, r - 1) - sum(t, l - 1);
    }

    long sum(long[] t, int i) {
        long res = 0;
        for (int x = i; x >= 0; x = (x & x + 1) - 1) res += t[x];
        return res;
    }

    void add(long[] t, int i, long delta) {
        for (int x = i; x < n; x = x | x + 1) t[x] += delta;
    }

    long mul(long a, long b) {
        return a * b % MOD;
    }

    long norm(long a) {
        a %= MOD;
        if (a > MOD) a -= MOD;
        if (a < 0) a += MOD;
        return a;
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new PuttingBoxesTogether().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


import java.io.*;
import java.util.*;

public class E {

    final int MAX = 85;

    double[][] prob;
    int[] parent;
    int n;

    public void solve() {
        int q = in.nextInt();
        int[] t = new int[q], v = new int[q];
        n = 1;
        for (int i = 0; i < q; i++) {
            t[i] = in.nextInt();
            v[i] = in.nextInt() - 1;
            if (t[i] == 1) {
                n++;
            }
        }

        parent = new int[n];
        parent[0] = -1;
        prob = new double[n][MAX];
        Arrays.fill(prob[0], 1);
        int last = 0;
        for (int i = 0; i < q; i++) {
            if (t[i] == 1) {
                last++;
                parent[last] = v[i];
            }
        }

        last = 0;
        for (int i = 0; i < q; i++) {
            if (t[i] == 1) {
                last++;
                addVertex(last);
            } else {
                double result = 0;
                double[] pr = prob[v[i]];
                for (int j = 0; j < MAX; j++) {
                    result += 1 - pr[j];
                }
                out.println(result);
            }
        }
    }

    private void addVertex(int v) {
        Arrays.fill(prob[v], 1);

        int p = parent[v];
        double last = 1;
        for (int i = 0; i < MAX; i++) {
            if (p == -1) {
                break;
            }
            double tmp = prob[p][i];
            prob[p][i] /= (0.5 + 0.5 * last);
            last = tmp;
            p = parent[p];
        }
        p = parent[v];

        last = 0;
        for (int i = 0; i < MAX; i++) {
            if (p == -1) {
                break;
            }
            prob[p][i] *= (0.5 + 0.5 * last);
            last = prob[p][i];
            p = parent[p];
        }
    }

    public void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    FastScanner in;
    PrintWriter out;

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        new E().run();
    }
}