import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
immutable MOD = 1_000_000_007;

auto solve(string s_)
{
    auto NC = s_.split.map!(to!int);
    immutable N=NC[0], C=NC[1];
    immutable A = readln.split.map!(to!long).array();
    immutable B = readln.split.map!(to!long).array();
    immutable u = B.reduce!max();
    auto p = new long[][](u+1,C+1);
    foreach(int v, ref a;p)
    {
        a[0]=1;
        foreach(c;1..C+1) a[c]=a[c-1]*v%MOD;
    }
    foreach(c;0..C+1) foreach(v;1..u+1) p[v][c]=(p[v][c]+p[v-1][c])%MOD;
    auto dp = new long[][](N+1,C+1);
    dp[0][0]=1;
    foreach(n;1..N+1)
    {
        auto a = p[A[n-1]-1];
        auto b = p[B[n-1]];
        foreach(c;0..C+1)
            foreach(i;0..c+1)
                dp[n][c]=(dp[n][c]+dp[n-1][i]*(b[c-i]-a[c-i]))%MOD;
    }
    return dp[N][C];
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }