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

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

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

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

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

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

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

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

n.x = j
j.p = c
k.u = c
k.p = n
e.p = c
m.u = k
m.p = n
a.p = k
g.p = m
c.u = k
c.p = n
assert c.p.x.p.txt == "c"