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

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

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

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

a = A("a")
i = B("i")
b = C("b")
h = D("h")

a.y = b
a.q = b
a.s = b
i.v = b
b.y = h
b.r = i
b.w = i
h.q = i
assert i.v.y.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.q: C = None
        self.s: C = None
        self.txt = txt

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

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

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

a = A("a")
i = B("i")
b = C("b")
h = D("h")

a.y = b
a.q = b
a.s = b
i.v = b
b.y = h
b.r = i
b.w = i
h.q = i
assert i.v.y.q.v.txt == "b"