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

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

a = A("a")
f = B("f")
l = B("l")

a.z = l
f.q = l
l.q = f
assert f.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
l = B("l")

a.z = l
f.q = l
l.q = f
assert f.q.q.q.txt == "l"