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

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

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

f = A("f")
d = B("d")
a = C("a")
h = A("h")
i = A("i")
n = C("n")

f.t = i
d.z = n
d.x = n
a.t = i
a.y = i
h.t = f
i.t = f
n.t = i
n.y = f
assert a.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
a = C("a")
h = A("h")
i = A("i")
n = C("n")

f.t = i
d.z = n
d.x = n
a.t = i
a.y = i
h.t = f
i.t = f
n.t = i
n.y = f
assert a.t.t.t.txt == "i"