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

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

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

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

f.t = d
h.y = f
h.s = d
a.p = h
a.t = n
n.y = f
n.s = a
k.y = f
k.s = d
d.p = k
d.t = n
assert d.t.s.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

f.t = d
h.y = f
h.s = d
a.p = h
a.t = n
n.y = f
n.s = a
k.y = f
k.s = d
d.p = k
d.t = n
assert d.t.s.t.y.txt == "f"