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

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

c = A("c")
a = B("a")
n = A("n")
e = B("e")

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

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

c = A("c")
a = B("a")
n = A("n")
e = B("e")

c.p = a
a.w = n
n.p = a
e.w = c
assert e.w.p.w.p.txt == "a"