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

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

n = A("n")
e = B("e")
d = B("d")
c = B("c")
f = B("f")
m = A("m")
k = B("k")

n.p = e
n.s = k
e.x = n
d.x = n
c.x = m
f.x = n
m.p = e
m.s = c
k.x = n
assert d.x.s.x.p.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

n = A("n")
e = B("e")
d = B("d")
c = B("c")
f = B("f")
m = A("m")
k = B("k")

n.p = e
n.s = k
e.x = n
d.x = n
c.x = m
f.x = n
m.p = e
m.s = c
k.x = n
assert d.x.s.x.p.x.s.x.txt == "n"