def get_lrmost(T, segs):
    """
    Finds the leftmost and rightmost segments of segs in T
    """
    l = []
    for s in list(T):
        if s in segs:
            l.append(s)
    if len(l) < 1:
        return None, None
    return l[0], l[-1]