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.u: B = None
        self.r: A = None
        self.txt = txt

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

d.w = k
d.q = i
i.u = l
i.r = k
l.u = i
l.r = b
k.w = d
k.q = l
b.w = k
b.q = l
assert k.q.u.u.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.u: B = None
        self.r: A = None
        self.txt = txt

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

d.w = k
d.q = i
i.u = l
i.r = k
l.u = i
l.r = b
k.w = d
k.q = l
b.w = k
b.q = l
assert k.q.u.u.txt == "l"