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

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

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

l = A("l")
n = B("n")
m = C("m")
i = A("i")
k = B("k")

l.w = n
n.w = k
n.v = m
n.x = m
m.q = n
m.r = k
m.w = l
i.w = n
k.w = n
k.v = m
k.x = m
assert l.w.x.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

l = A("l")
n = B("n")
m = C("m")
i = A("i")
k = B("k")

l.w = n
n.w = k
n.v = m
n.x = m
m.q = n
m.r = k
m.w = l
i.w = n
k.w = n
k.v = m
k.x = m
assert l.w.x.q.w.txt == "k"