def buildIndirectMapping(a, b):
    """Given a maps x->y, b maps y->z, return map of x->z."""
    assert(len(a) == len(b))
    assert(isinstance(list(b.keys())[0], type(list(a.values())[0])))
    c = dict()
    for x in a.keys():
        y = a[x]
        z = b[y]
        c[x] = z
    return c