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

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

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

class D:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: A = None
        self.r: A = None
        self.t: B = None
        self.txt = txt

b = A("b")
d = B("d")
m = C("m")
h = D("h")

b.s = d
b.r = d
d.v = h
d.s = h
m.t = h
h.y = d
h.t = d
h.z = b
h.r = b
assert d.v.z.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.r: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.y: B = None
        self.z: A = None
        self.r: A = None
        self.t: B = None
        self.txt = txt

b = A("b")
d = B("d")
m = C("m")
h = D("h")

b.s = d
b.r = d
d.v = h
d.s = h
m.t = h
h.y = d
h.t = d
h.z = b
h.r = b
assert d.v.z.r.v.txt == "h"