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

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

k = A("k")
n = B("n")
h = A("h")
i = A("i")

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

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

k = A("k")
n = B("n")
h = A("h")
i = A("i")

k.y = h
n.w = k
h.y = k
i.y = h
assert h.y.y.y.y.txt == "h"