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

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

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

m = A("m")
f = B("f")
g = C("g")
c = B("c")
d = B("d")
a = C("a")
k = A("k")
h = B("h")

m.q = c
m.t = a
f.y = h
g.q = a
g.y = k
g.r = k
c.y = h
d.y = c
a.q = g
a.y = k
a.r = k
k.q = c
k.t = g
h.y = d
assert m.q.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
g = C("g")
c = B("c")
d = B("d")
a = C("a")
k = A("k")
h = B("h")

m.q = c
m.t = a
f.y = h
g.q = a
g.y = k
g.r = k
c.y = h
d.y = c
a.q = g
a.y = k
a.r = k
k.q = c
k.t = g
h.y = d
assert m.q.y.y.txt == "d"