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

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

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

g = A("g")
a = B("a")
e = C("e")
m = A("m")
k = A("k")
f = C("f")
d = A("d")
h = A("h")
j = B("j")

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

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

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

g = A("g")
a = B("a")
e = C("e")
m = A("m")
k = A("k")
f = C("f")
d = A("d")
h = A("h")
j = B("j")

g.x = h
a.x = e
a.y = j
a.u = f
e.z = h
e.r = f
m.x = k
k.x = d
f.z = h
f.r = e
d.x = k
h.x = m
j.x = e
j.u = e
j.y = a
assert e.z.x.x.x.txt == "d"