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

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

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

g = A("g")
i = B("i")
k = C("k")
m = B("m")
d = A("d")
h = C("h")

g.u = d
i.q = m
k.y = h
k.s = h
k.x = m
m.q = i
d.u = g
h.y = k
h.s = k
h.x = i
assert g.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
k = C("k")
m = B("m")
d = A("d")
h = C("h")

g.u = d
i.q = m
k.y = h
k.s = h
k.x = m
m.q = i
d.u = g
h.y = k
h.s = k
h.x = i
assert g.u.u.u.u.u.u.txt == "g"