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

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

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

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

h.t = d
f.x = g
f.y = g
e.o = h
e.q = g
e.y = d
g.o = h
g.y = h
g.q = e
d.t = k
k.t = h
assert f.x.o.t.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.x: C = None
        self.y: C = None
        self.txt = txt

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

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

h.t = d
f.x = g
f.y = g
e.o = h
e.q = g
e.y = d
g.o = h
g.y = h
g.q = e
d.t = k
k.t = h
assert f.x.o.t.t.t.t.txt == "d"