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

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

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

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

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

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

f.z = l
l.r = h
l.q = f
h.r = l
h.q = f
assert l.q.z.q.txt == "f"