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

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

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

e = A("e")
f = B("f")
c = C("c")
h = A("h")
n = B("n")
k = B("k")
a = C("a")
d = C("d")

e.x = d
e.r = h
f.u = h
c.r = e
c.p = d
c.s = d
h.x = a
h.r = e
n.u = h
k.u = h
a.r = h
a.p = d
a.s = c
d.r = e
d.p = a
d.s = a
assert n.u.x.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.r: A = None
        self.txt = txt

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

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

e = A("e")
f = B("f")
c = C("c")
h = A("h")
n = B("n")
k = B("k")
a = C("a")
d = C("d")

e.x = d
e.r = h
f.u = h
c.r = e
c.p = d
c.s = d
h.x = a
h.r = e
n.u = h
k.u = h
a.r = h
a.p = d
a.s = c
d.r = e
d.p = a
d.s = a
assert n.u.x.p.r.txt == "e"