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

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

k = A("k")
f = B("f")
h = A("h")
e = B("e")
i = A("i")
d = A("d")

k.y = d
f.t = e
h.y = k
e.t = f
i.y = d
d.y = i
assert e.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

k = A("k")
f = B("f")
h = A("h")
e = B("e")
i = A("i")
d = A("d")

k.y = d
f.t = e
h.y = k
e.t = f
i.y = d
d.y = i
assert e.t.t.t.txt == "f"