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

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

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

h = A("h")
e = B("e")
b = C("b")
c = A("c")
n = B("n")
a = A("a")
k = C("k")

h.q = e
h.x = k
e.t = b
b.p = c
b.w = c
b.q = n
c.q = n
c.x = b
n.t = k
a.q = n
a.x = k
k.p = h
k.w = h
k.q = n
assert h.q.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.x: C = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
b = C("b")
c = A("c")
n = B("n")
a = A("a")
k = C("k")

h.q = e
h.x = k
e.t = b
b.p = c
b.w = c
b.q = n
c.q = n
c.x = b
n.t = k
a.q = n
a.x = k
k.p = h
k.w = h
k.q = n
assert h.q.t.p.txt == "c"