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

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

b = A("b")
l = B("l")
d = B("d")

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

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

b = A("b")
l = B("l")
d = B("d")

b.x = d
b.q = l
l.z = d
l.x = d
d.z = l
d.x = l
assert d.x.x.z.txt == "l"