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

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

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

h = A("h")
e = B("e")
n = C("n")
d = B("d")
k = A("k")
l = C("l")
c = C("c")
g = B("g")
m = B("m")

h.t = k
h.q = c
e.t = h
e.x = k
n.r = c
d.t = h
d.x = h
k.t = h
k.q = l
l.r = n
c.r = n
g.t = h
g.x = k
m.t = h
m.x = k
assert h.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: C = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
n = C("n")
d = B("d")
k = A("k")
l = C("l")
c = C("c")
g = B("g")
m = B("m")

h.t = k
h.q = c
e.t = h
e.x = k
n.r = c
d.t = h
d.x = h
k.t = h
k.q = l
l.r = n
c.r = n
g.t = h
g.x = k
m.t = h
m.x = k
assert h.q.r.r.txt == "c"