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

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

d = A("d")
i = B("i")
c = B("c")
l = A("l")
k = B("k")

d.w = l
d.x = k
i.w = l
c.w = d
l.w = d
l.x = c
k.w = l
assert l.x.w.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.x: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
c = B("c")
l = A("l")
k = B("k")

d.w = l
d.x = k
i.w = l
c.w = d
l.w = d
l.x = c
k.w = l
assert l.x.w.w.x.txt == "c"