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

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

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

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

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

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

b.z = e
h.q = b
e.z = b
f.q = b
assert f.q.z.z.txt == "b"