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

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

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

m = A("m")
i = B("i")
b = C("b")
h = C("h")
f = B("f")
e = C("e")
g = A("g")

m.p = g
m.u = b
m.z = f
i.q = f
b.v = f
b.r = h
h.v = f
h.r = e
f.q = i
e.v = f
e.r = h
g.p = m
g.u = e
g.z = f
assert i.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: C = None
        self.z: B = None
        self.txt = txt

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

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

m = A("m")
i = B("i")
b = C("b")
h = C("h")
f = B("f")
e = C("e")
g = A("g")

m.p = g
m.u = b
m.z = f
i.q = f
b.v = f
b.r = h
h.v = f
h.r = e
f.q = i
e.v = f
e.r = h
g.p = m
g.u = e
g.z = f
assert i.q.q.q.q.q.q.txt == "i"