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

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

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

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

h = A("h")
c = B("c")
e = C("e")
i = D("i")
d = A("d")

h.q = i
h.z = d
c.q = i
e.w = i
e.y = c
i.o = e
d.q = i
d.z = h
assert i.o.y.q.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.z: A = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
e = C("e")
i = D("i")
d = A("d")

h.q = i
h.z = d
c.q = i
e.w = i
e.y = c
i.o = e
d.q = i
d.z = h
assert i.o.y.q.o.w.txt == "i"