#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
vector<long long> pow2;

long long calc(const string &n, const string &mask) {
    int length = n.length();
    vector<int> zeros_suffix(length + 1, 0);
    
    for (int i = length - 1; i >= 0; --i) {
        zeros_suffix[i] = zeros_suffix[i + 1] + (mask[i] == '0' ? 1 : 0);
    }

    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') {
                ans = (ans + pow2[zeros_suffix[i + 1]]) % MOD;
            }
        }
    }
    ans = (ans + 1) % MOD;
    return ans;
}

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

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

    string l_bin = bitset<64>(stoull(l, nullptr, 16)).to_string().substr(64 - max_len);
    string r_bin = bitset<64>(stoull(r, nullptr, 16)).to_string().substr(64 - max_len);
    string b_bin = bitset<64>(stoull(b, nullptr, 16)).to_string().substr(64 - max_len);
    pow2.resize(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) 
                     + ((stoull(l, nullptr, 16) & stoull(b, nullptr, 16)) == stoull(b, nullptr, 16) ? 1 : 0) 
                     + MOD) % MOD;
    cout << res << endl;

    return 0;
}

