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

class B:
    def __init__(self, txt: str):
        self.x: A = 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.s: D = None
        self.txt = txt

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

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

class B:
    def __init__(self, txt: str):
        self.x: A = 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.s: D = None
        self.txt = txt

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

i.r = c
i.x = c
c.x = i
m.v = i
h.s = d
d.s = h
b.s = d
assert d.s.s.s.txt == "h"