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

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

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

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

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

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

e.z = b
b.t = m
b.q = f
m.z = f
f.t = m
f.q = b
assert f.q.t.z.txt == "f"