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

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

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

class D:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: C = None
        self.txt = txt

h = A("h")
f = B("f")
i = C("i")
m = D("m")
e = D("e")

h.y = m
h.u = i
h.z = e
f.v = h
f.x = e
f.z = i
f.q = i
i.r = h
i.v = f
m.t = h
m.p = i
e.t = h
e.p = i
assert e.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: C = None
        self.z: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: C = None
        self.txt = txt

h = A("h")
f = B("f")
i = C("i")
m = D("m")
e = D("e")

h.y = m
h.u = i
h.z = e
f.v = h
f.x = e
f.z = i
f.q = i
i.r = h
i.v = f
m.t = h
m.p = i
e.t = h
e.p = i
assert e.p.v.v.txt == "h"