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

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

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

e.p = h
h.w = i
i.w = h
c.p = i
assert e.p.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

e.p = h
h.w = i
i.w = h
c.p = i
assert e.p.w.w.txt == "h"