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

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

a = A("a")
n = B("n")
k = A("k")
d = A("d")
i = B("i")

a.w = k
n.x = i
n.y = i
k.w = d
d.w = k
i.x = n
i.y = n
assert d.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
k = A("k")
d = A("d")
i = B("i")

a.w = k
n.x = i
n.y = i
k.w = d
d.w = k
i.x = n
i.y = n
assert d.w.w.w.w.w.txt == "k"