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

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

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

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

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

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

l.x = b
l.z = a
b.s = l
b.q = a
a.x = b
a.z = l
f.x = b
f.z = l
assert f.x.s.z.txt == "a"