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

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

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

c = A("c")
k = B("k")
a = C("a")
g = B("g")
i = B("i")
j = B("j")
m = C("m")
h = B("h")

c.u = a
c.x = h
k.r = a
a.t = c
a.p = c
g.r = a
i.r = a
j.r = a
m.t = c
m.p = c
h.r = m
assert j.r.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.x: B = None
        self.txt = txt

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

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

c = A("c")
k = B("k")
a = C("a")
g = B("g")
i = B("i")
j = B("j")
m = C("m")
h = B("h")

c.u = a
c.x = h
k.r = a
a.t = c
a.p = c
g.r = a
i.r = a
j.r = a
m.t = c
m.p = c
h.r = m
assert j.r.t.x.txt == "h"