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

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

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

a = A("a")
n = B("n")
j = C("j")
m = B("m")
i = A("i")
b = B("b")
d = C("d")
l = B("l")
e = C("e")

a.w = d
a.q = n
n.q = a
j.x = a
m.q = i
i.w = e
i.q = m
b.q = a
d.x = a
l.q = i
e.x = i
assert n.q.w.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.q: B = None
        self.txt = txt

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

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

a = A("a")
n = B("n")
j = C("j")
m = B("m")
i = A("i")
b = B("b")
d = C("d")
l = B("l")
e = C("e")

a.w = d
a.q = n
n.q = a
j.x = a
m.q = i
i.w = e
i.q = m
b.q = a
d.x = a
l.q = i
e.x = i
assert n.q.w.x.w.x.txt == "a"