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

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

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

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

i = A("i")
j = B("j")
g = C("g")
h = D("h")

i.q = h
j.s = h
g.o = i
g.w = i
g.z = h
g.y = j
h.v = i
assert j.s.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

i = A("i")
j = B("j")
g = C("g")
h = D("h")

i.q = h
j.s = h
g.o = i
g.w = i
g.z = h
g.y = j
h.v = i
assert j.s.v.q.txt == "h"