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

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

k = A("k")
d = B("d")
h = A("h")
g = B("g")

k.y = h
d.u = k
h.y = k
g.u = h
assert k.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.u: A = None
        self.txt = txt

k = A("k")
d = B("d")
h = A("h")
g = B("g")

k.y = h
d.u = k
h.y = k
g.u = h
assert k.y.y.y.y.txt == "k"