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

class B:
    def __init__(self, txt: str):
        self.v: E = None
        self.p: E = None
        self.t: C = None
        self.x: D = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
b = C("b")
f = D("f")
m = E("m")

n.x = g
g.v = m
g.p = m
g.t = b
g.x = f
b.w = n
b.z = m
f.z = m
f.v = n
m.t = f
m.q = f
m.v = f
m.r = g
assert m.r.x.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: E = None
        self.p: E = None
        self.t: C = None
        self.x: D = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
b = C("b")
f = D("f")
m = E("m")

n.x = g
g.v = m
g.p = m
g.t = b
g.x = f
b.w = n
b.z = m
f.z = m
f.v = n
m.t = f
m.q = f
m.v = f
m.r = g
assert m.r.x.v.x.txt == "g"