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

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

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

b = A("b")
d = B("d")
a = C("a")
i = A("i")
m = B("m")
f = B("f")

b.q = i
d.s = b
d.x = a
d.w = a
a.u = i
a.y = d
i.q = b
m.s = i
m.x = a
m.w = a
f.s = i
f.x = a
f.w = a
assert a.y.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

b = A("b")
d = B("d")
a = C("a")
i = A("i")
m = B("m")
f = B("f")

b.q = i
d.s = b
d.x = a
d.w = a
a.u = i
a.y = d
i.q = b
m.s = i
m.x = a
m.w = a
f.s = i
f.x = a
f.w = a
assert a.y.s.q.txt == "i"