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

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

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

d = A("d")
l = B("l")
b = C("b")
h = A("h")
i = C("i")
m = C("m")
k = B("k")
a = C("a")

d.u = h
d.o = h
l.p = d
b.x = m
h.u = d
h.o = d
i.x = b
m.x = b
k.p = d
a.x = m
assert d.u.u.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: A = None
        self.txt = txt

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

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

d = A("d")
l = B("l")
b = C("b")
h = A("h")
i = C("i")
m = C("m")
k = B("k")
a = C("a")

d.u = h
d.o = h
l.p = d
b.x = m
h.u = d
h.o = d
i.x = b
m.x = b
k.p = d
a.x = m
assert d.u.u.o.o.txt == "d"