class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.v: A = None
        self.txt = txt

m = A("m")
b = B("b")
e = B("e")
l = A("l")
f = B("f")

m.q = b
b.t = m
b.v = l
e.t = l
e.v = l
l.q = e
f.t = l
f.v = l
assert b.v.q.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.v: A = None
        self.txt = txt

m = A("m")
b = B("b")
e = B("e")
l = A("l")
f = B("f")

m.q = b
b.t = m
b.v = l
e.t = l
e.v = l
l.q = e
f.t = l
f.v = l
assert b.v.q.t.q.t.txt == "l"