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

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

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

a = A("a")
i = B("i")
g = C("g")
b = B("b")
c = B("c")
d = C("d")
k = C("k")
h = B("h")
n = B("n")
f = C("f")

a.s = n
i.q = k
g.x = i
b.q = d
c.q = d
d.x = i
k.x = h
h.q = k
n.q = k
f.x = h
assert g.x.q.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
g = C("g")
b = B("b")
c = B("c")
d = C("d")
k = C("k")
h = B("h")
n = B("n")
f = C("f")

a.s = n
i.q = k
g.x = i
b.q = d
c.q = d
d.x = i
k.x = h
h.q = k
n.q = k
f.x = h
assert g.x.q.x.q.x.txt == "h"