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

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

c = A("c")
a = B("a")
d = B("d")
l = A("l")

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

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

c = A("c")
a = B("a")
d = B("d")
l = A("l")

c.w = l
c.q = a
a.z = d
a.w = l
d.z = a
d.w = l
l.w = c
l.q = a
assert d.z.z.w.w.txt == "c"