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

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

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

h = A("h")
m = B("m")
b = C("b")
i = A("i")
n = A("n")
f = C("f")
e = B("e")
a = B("a")
l = B("l")

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

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

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

h = A("h")
m = B("m")
b = C("b")
i = A("i")
n = A("n")
f = C("f")
e = B("e")
a = B("a")
l = B("l")

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