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

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

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

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

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

d = A("d")
f = B("f")
j = C("j")
n = D("n")
g = E("g")

d.x = g
f.x = j
f.r = n
j.r = f
j.v = d
n.z = d
g.z = j
assert j.v.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: E = None
        self.txt = txt

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

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

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

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

d = A("d")
f = B("f")
j = C("j")
n = D("n")
g = E("g")

d.x = g
f.x = j
f.r = n
j.r = f
j.v = d
n.z = d
g.z = j
assert j.v.x.z.txt == "j"