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

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

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

h = A("h")
f = B("f")
g = C("g")
b = C("b")
l = A("l")
k = B("k")
a = C("a")
d = A("d")

h.u = a
f.p = l
f.z = h
f.q = g
g.x = b
b.x = g
l.u = a
k.p = l
k.z = l
k.q = b
a.x = g
d.u = b
assert b.x.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
g = C("g")
b = C("b")
l = A("l")
k = B("k")
a = C("a")
d = A("d")

h.u = a
f.p = l
f.z = h
f.q = g
g.x = b
b.x = g
l.u = a
k.p = l
k.z = l
k.q = b
a.x = g
d.u = b
assert b.x.x.x.x.x.x.x.x.txt == "b"