#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1000000007;
vector<long long> pow2;

long long calc(const string& n, const string& mask) {
    int len = n.size();
    vector<int> zeros(len + 1, 0);

    for (int i = len - 1; i >= 0; i--) {
        if (mask[i] == '0')
            zeros[i] = zeros[i + 1] + 1;
        else
            zeros[i] = zeros[i + 1];
    }

    long long ans = 0;

    for (int i = 0; i < len; i++) {
        if (mask[i] == '1') {
            if (n[i] == '0')
                return ans;
        } else {
            if (n[i] == '1')
                ans = (ans + pow2[zeros[i + 1]]) % MOD;
        }
    }

    return (ans + 1) % MOD;
}

string toBin(string hex, int len) {
    string bin;

    for (char c : hex) {
        int x;
        if (c <= '9')
            x = c - '0';
        else
            x = c - 'A' + 10;

        for (int i = 3; i >= 0; i--) {
            bin += ((x >> i) & 1) + '0';
        }
    }

    int pos = 0;
    while (pos < (int)bin.size() && bin[pos] == '0') {
        pos++;
    }

    if (pos == (int)bin.size()) {
        bin = "0";
    } else {
        bin = bin.substr(pos);
    }

    if ((int)bin.size() < len) {
        bin = string(len - bin.size(), '0') + bin;
    }

    return bin;
}

bool valid(const string& l, const string& b) {
    for (int i = 0; i < (int)l.size(); i++) {
        if (b[i] == '1' && l[i] == '0')
            return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string l, r, b;
    cin >> l >> r >> b;

    int len = max((int)l.size(), max((int)r.size(), (int)b.size())) * 4;

    string lb = toBin(l, len);
    string rb = toBin(r, len);
    string bb = toBin(b, len);

    pow2.resize(len + 1);
    pow2[0] = 1;

    for (int i = 1; i <= len; i++) {
        pow2[i] = (pow2[i - 1] * 2) % MOD;
    }

    long long ans = calc(rb, bb) - calc(lb, bb);

    if (valid(lb, bb))
        ans++;

    ans = (ans % MOD + MOD) % MOD;

    cout << ans << '\n';

    return 0;
}
