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

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

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

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

a = A("a")
m = B("m")
j = C("j")
k = D("k")
g = D("g")
h = B("h")
l = C("l")

a.y = g
m.v = h
m.q = a
m.y = l
j.z = a
k.y = l
g.y = j
h.v = m
h.q = a
h.y = j
l.z = a
assert k.y.z.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

a = A("a")
m = B("m")
j = C("j")
k = D("k")
g = D("g")
h = B("h")
l = C("l")

a.y = g
m.v = h
m.q = a
m.y = l
j.z = a
k.y = l
g.y = j
h.v = m
h.q = a
h.y = j
l.z = a
assert k.y.z.y.y.txt == "j"