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

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

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

n = A("n")
m = B("m")
e = C("e")
a = B("a")
d = A("d")
j = C("j")

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

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

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

n = A("n")
m = B("m")
e = C("e")
a = B("a")
d = A("d")
j = C("j")

n.p = d
n.x = a
m.s = d
m.r = e
m.x = e
e.x = n
e.p = j
a.s = d
a.r = e
a.x = e
d.p = n
d.x = a
j.x = d
j.p = e
assert m.s.x.r.x.x.s.txt == "d"