class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: C = 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: B = None
        self.y: A = None
        self.s: C = None
        self.txt = txt

m = A("m")
k = B("k")
f = C("f")
h = B("h")
g = C("g")
j = A("j")

m.u = h
m.r = f
k.p = g
f.u = h
f.y = j
f.s = g
h.p = g
g.u = h
g.y = j
g.s = f
j.u = h
j.r = f
assert f.s.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: C = 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: B = None
        self.y: A = None
        self.s: C = None
        self.txt = txt

m = A("m")
k = B("k")
f = C("f")
h = B("h")
g = C("g")
j = A("j")

m.u = h
m.r = f
k.p = g
f.u = h
f.y = j
f.s = g
h.p = g
g.u = h
g.y = j
g.s = f
j.u = h
j.r = f
assert f.s.y.u.txt == "h"