#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

long long calc(const string& n, const string& mask) {
    int length = n.size();
    long long ans = 0;

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

    ans = (ans + 1) % MOD;
    return ans;
}

string hexCharToBin(char c) {
    switch (c) {
        case '0': return "0000";
        case '1': return "0001";
        case '2': return "0010";
        case '3': return "0011";
        case '4': return "0100";
        case '5': return "0101";
        case '6': return "0110";
        case '7': return "0111";
        case '8': return "1000";
        case '9': return "1001";
        case 'A': return "1010";
        case 'B': return "1011";
        case 'C': return "1100";
        case 'D': return "1101";
        case 'E': return "1110";
        case 'F': return "1111";
    }
    return "";
}

string hex2bin(const string& x, int max_len) {
    string res = "";
    for (char c : x) {
        res += hexCharToBin(c);
    }

    return string(max_len - res.size(), '0') + res;
}

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

int main() {
    string l, r, b;
    cin >> l >> r >> b;

    int max_len = max({(int)l.size(), (int)r.size(), (int)b.size()}) * 4;

    string l_bin = hex2bin(l, max_len);
    string r_bin = hex2bin(r, max_len);
    string b_bin = hex2bin(b, max_len);

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

    long long res = (
        calc(r_bin, b_bin)
        - calc(l_bin, b_bin)
        + (checkMask(l_bin, b_bin) ? 1 : 0)
        + MOD
    ) % MOD;

    cout << res << endl;

    return 0;
}
