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

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

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

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

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

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

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

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

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

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

i.r = b
h.q = c
b.y = c
b.v = c
b.z = h
b.s = n
n.w = h
e.w = h
c.r = b
assert e.w.q.r.z.q.txt == "c"