#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long

using namespace std;
const int MOD = 1000000007;
const int Mmax = 4004, Nmax = 4004;
// using static array instead of vector to decrease the running time
int Ri[Mmax][Nmax], Do[Mmax][Nmax], A[Mmax], B[Nmax];
ll res[Mmax][Nmax];

int main()
{
    if (fopen("JUMP.INP", "r")) {
        freopen("JUMP.INP", "r", stdin);
        freopen("JUMP.OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int m, n, k;
    // using scanf() instead of cin to decrease the running time
    scanf("%d %d %d", &m, &n, &k);
    for (int i = 1; i <= m; ++i) {
        scanf("%d", &A[i]);
        A[i] %= k; // we take modulo of A[i] first for later purpose
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &B[i]);
        B[i] %= k; // we take modulo of B[i] first for later purpose
    }
    res[m][n] = Ri[m][n] = Do[m][n] = 1;
    for (int i = m; i > 0; --i) {
        for (int j = n; j > 0; --j) {
            int val = A[i] + B[j];
            if (val >= k) val -= k; // calculate (A[i] + B[j]) % k avoid using mod '%'
            res[i][j] += Ri[i][j + 1] - Ri[i][min(j + 2 + val, n + 1)] + MOD;
            res[i][j] += Do[i + 1][j] - Do[min(i + 2 + val, m + 1)][j] + MOD;
            while (res[i][j] >= MOD) res[i][j] -= MOD; // calculate res[i][j] % MOD avoid using mod '%'
            Ri[i][j] = Ri[i][j + 1] + res[i][j];
            Do[i][j] = Do[i + 1][j] + res[i][j];
            if (Ri[i][j] >= MOD) Ri[i][j] -= MOD; // calculate Ri[i][j] % MOD avoid using mod '%'
            if (Do[i][j] >= MOD) Do[i][j] -= MOD; // calculate Do[i][j] % MOD avoid using mod '%'
        }
    }
    cout << res[1][1];
    return 0;
}