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

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

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

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

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

j.r = l
j.x = l
d.r = l
l.v = j
h.v = l
h.w = l
h.x = j
h.s = d
i.v = l
i.w = l
i.x = j
i.s = d
assert d.r.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: C = None
        self.txt = txt

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

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

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

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

j.r = l
j.x = l
d.r = l
l.v = j
h.v = l
h.w = l
h.x = j
h.s = d
i.v = l
i.w = l
i.x = j
i.s = d
assert d.r.v.r.v.txt == "j"