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

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

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

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

j = A("j")
a = B("a")
c = C("c")
h = D("h")
l = A("l")
m = D("m")
i = C("i")

j.x = h
a.s = m
a.q = h
a.x = j
c.z = a
h.y = j
h.s = l
l.x = h
m.y = j
m.s = l
i.z = a
assert h.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

j = A("j")
a = B("a")
c = C("c")
h = D("h")
l = A("l")
m = D("m")
i = C("i")

j.x = h
a.s = m
a.q = h
a.x = j
c.z = a
h.y = j
h.s = l
l.x = h
m.y = j
m.s = l
i.z = a
assert h.y.x.y.txt == "j"