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

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

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

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

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

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

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

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

g.w = i
l.x = m
l.y = g
e.z = g
e.q = n
e.v = n
i.w = g
n.z = i
n.q = m
n.v = e
m.z = i
m.q = e
m.v = e
assert e.z.w.w.w.w.txt == "g"