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

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

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

g = A("g")
k = B("k")
i = C("i")
l = A("l")
e = B("e")
n = C("n")

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

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

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

g = A("g")
k = B("k")
i = C("i")
l = A("l")
e = B("e")
n = C("n")

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