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

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

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

a = A("a")
b = B("b")
h = C("h")
i = B("i")
f = A("f")
n = C("n")
g = A("g")

a.p = g
b.o = i
h.t = n
h.r = n
h.u = b
i.o = b
f.p = a
n.t = h
n.r = h
n.u = b
g.p = a
assert b.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

a = A("a")
b = B("b")
h = C("h")
i = B("i")
f = A("f")
n = C("n")
g = A("g")

a.p = g
b.o = i
h.t = n
h.r = n
h.u = b
i.o = b
f.p = a
n.t = h
n.r = h
n.u = b
g.p = a
assert b.o.o.o.o.txt == "b"