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

class B:
    def __init__(self, txt: str):
        self.w: B = None
        self.u: D = None
        self.txt = txt

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

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

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

j.y = n
k.w = a
k.u = h
n.y = a
h.o = n
h.q = j
a.w = k
a.u = l
l.o = n
l.q = j
assert a.w.w.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: B = None
        self.u: D = None
        self.txt = txt

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

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

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

j.y = n
k.w = a
k.u = h
n.y = a
h.o = n
h.q = j
a.w = k
a.u = l
l.o = n
l.q = j
assert a.w.w.u.q.txt == "j"