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

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: C = None
        self.o: C = None
        self.v: C = None
        self.q: D = None
        self.txt = txt

g = A("g")
e = B("e")
b = C("b")
m = D("m")
i = E("i")
a = D("a")

g.v = e
e.r = g
b.z = g
m.r = g
m.q = i
m.x = e
i.s = b
i.o = b
i.v = b
i.q = m
a.r = g
a.q = i
a.x = e
assert g.v.r.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.s: C = None
        self.o: C = None
        self.v: C = None
        self.q: D = None
        self.txt = txt

g = A("g")
e = B("e")
b = C("b")
m = D("m")
i = E("i")
a = D("a")

g.v = e
e.r = g
b.z = g
m.r = g
m.q = i
m.x = e
i.s = b
i.o = b
i.v = b
i.q = m
a.r = g
a.q = i
a.x = e
assert g.v.r.v.r.v.txt == "e"