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

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

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

n = A("n")
a = B("a")
g = C("g")
m = C("m")
e = A("e")
c = B("c")

n.r = c
a.p = e
a.x = e
a.u = e
g.o = c
g.x = m
m.o = a
m.x = g
e.r = a
c.p = e
c.u = e
c.x = n
assert c.u.r.x.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

n = A("n")
a = B("a")
g = C("g")
m = C("m")
e = A("e")
c = B("c")

n.r = c
a.p = e
a.x = e
a.u = e
g.o = c
g.x = m
m.o = a
m.x = g
e.r = a
c.p = e
c.u = e
c.x = n
assert c.u.r.x.r.p.txt == "e"