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

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

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

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

b.y = k
b.p = h
b.u = i
i.y = m
i.p = m
i.r = b
j.z = i
j.p = k
m.y = i
m.p = i
m.r = b
h.z = m
h.p = k
f.z = m
f.p = j
k.z = m
k.p = j
assert f.p.p.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.p: C = None
        self.u: B = None
        self.txt = txt

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

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

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

b.y = k
b.p = h
b.u = i
i.y = m
i.p = m
i.r = b
j.z = i
j.p = k
m.y = i
m.p = i
m.r = b
h.z = m
h.p = k
f.z = m
f.p = j
k.z = m
k.p = j
assert f.p.p.p.z.txt == "i"