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

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

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

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

g.q = h
l.t = h
l.v = g
l.x = m
f.s = m
d.t = h
d.v = g
d.x = a
a.q = d
h.t = l
h.v = m
h.x = m
b.t = l
b.v = m
b.x = a
m.q = b
assert b.x.q.x.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

g.q = h
l.t = h
l.v = g
l.x = m
f.s = m
d.t = h
d.v = g
d.x = a
a.q = d
h.t = l
h.v = m
h.x = m
b.t = l
b.v = m
b.x = a
m.q = b
assert b.x.q.x.q.x.q.txt == "d"