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

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

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

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

b = A("b")
c = B("c")
d = C("d")
h = D("h")
k = B("k")

b.v = d
b.s = d
c.r = h
c.w = b
c.q = b
d.z = b
h.s = d
h.p = d
h.u = k
h.v = k
k.r = h
k.w = b
k.q = b
assert b.s.z.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.s: C = None
        self.txt = txt

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

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

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

b = A("b")
c = B("c")
d = C("d")
h = D("h")
k = B("k")

b.v = d
b.s = d
c.r = h
c.w = b
c.q = b
d.z = b
h.s = d
h.p = d
h.u = k
h.v = k
k.r = h
k.w = b
k.q = b
assert b.s.z.v.z.v.txt == "d"