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

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

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

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

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

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

k.s = e
k.p = i
h.y = k
e.s = i
e.p = k
i.s = k
i.p = k
assert i.s.p.p.s.txt == "e"