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

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

c = A("c")
b = B("b")
e = B("e")
i = A("i")
d = B("d")
h = B("h")

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

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

c = A("c")
b = B("b")
e = B("e")
i = A("i")
d = B("d")
h = B("h")

c.r = b
c.v = e
b.w = d
e.w = b
i.r = b
i.v = d
d.w = b
h.w = b
assert i.v.w.w.w.txt == "b"