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

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

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

h = A("h")
c = B("c")
n = C("n")
g = C("g")
f = C("f")
d = C("d")
k = A("k")
m = B("m")
e = A("e")

h.y = g
c.x = d
c.z = d
n.u = g
g.u = f
f.u = n
d.u = g
k.y = g
m.x = g
m.z = g
e.y = n
assert d.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
c = B("c")
n = C("n")
g = C("g")
f = C("f")
d = C("d")
k = A("k")
m = B("m")
e = A("e")

h.y = g
c.x = d
c.z = d
n.u = g
g.u = f
f.u = n
d.u = g
k.y = g
m.x = g
m.z = g
e.y = n
assert d.u.u.u.u.txt == "g"