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

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

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

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

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

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

k.o = c
k.s = e
e.w = k
e.p = k
c.o = k
c.s = n
n.w = k
n.p = c
assert e.p.o.s.w.txt == "k"