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

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

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

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

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

g.z = b
j.y = b
j.x = e
m.z = c
m.r = f
e.u = m
e.y = g
e.z = b
b.y = j
b.x = e
f.z = g
f.r = m
c.z = j
h.z = b
assert c.z.y.x.u.r.z.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

g.z = b
j.y = b
j.x = e
m.z = c
m.r = f
e.u = m
e.y = g
e.z = b
b.y = j
b.x = e
f.z = g
f.r = m
c.z = j
h.z = b
assert c.z.y.x.u.r.z.z.x.txt == "e"