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

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

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

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

h = A("h")
g = B("g")
m = C("m")
j = D("j")
e = A("e")

h.z = j
h.y = j
g.o = m
g.x = m
g.v = j
m.v = e
m.o = g
j.y = h
j.x = g
e.z = j
e.y = j
assert j.y.z.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.y: D = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
m = C("m")
j = D("j")
e = A("e")

h.z = j
h.y = j
g.o = m
g.x = m
g.v = j
m.v = e
m.o = g
j.y = h
j.x = g
e.z = j
e.y = j
assert j.y.z.y.z.y.txt == "h"