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

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

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

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

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

j.q = h
h.v = c
d.u = h
d.p = h
d.y = h
d.q = j
c.r = i
i.r = c
assert j.q.v.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

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

j.q = h
h.v = c
d.u = h
d.p = h
d.y = h
d.q = j
c.r = i
i.r = c
assert j.q.v.r.r.r.txt == "i"