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

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

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

k.z = n
k.r = n
l.w = n
b.w = l
n.w = l
d.w = n
assert d.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: B = None
        self.txt = txt

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

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

k.z = n
k.r = n
l.w = n
b.w = l
n.w = l
d.w = n
assert d.w.w.w.w.w.txt == "n"