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

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

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

h = A("h")
d = B("d")
n = C("n")
k = B("k")
b = A("b")
a = C("a")
e = B("e")
f = B("f")
m = B("m")

h.z = a
h.x = m
d.r = m
n.r = a
n.t = a
k.r = d
b.z = a
b.x = d
a.r = n
a.t = n
e.r = m
f.r = m
m.r = d
assert e.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: B = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
n = C("n")
k = B("k")
b = A("b")
a = C("a")
e = B("e")
f = B("f")
m = B("m")

h.z = a
h.x = m
d.r = m
n.r = a
n.t = a
k.r = d
b.z = a
b.x = d
a.r = n
a.t = n
e.r = m
f.r = m
m.r = d
assert e.r.r.r.r.r.r.txt == "d"