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

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

e.q = a
e.v = g
g.v = e
a.y = e
i.p = g
m.p = g
assert m.p.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.v: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

e.q = a
e.v = g
g.v = e
a.y = e
i.p = g
m.p = g
assert m.p.v.v.v.v.txt == "g"