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

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

b = A("b")
i = B("i")
d = A("d")
l = A("l")
m = B("m")

b.v = l
i.x = l
i.q = m
d.v = b
l.v = d
m.x = l
m.q = i
assert i.x.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

b = A("b")
i = B("i")
d = A("d")
l = A("l")
m = B("m")

b.v = l
i.x = l
i.q = m
d.v = b
l.v = d
m.x = l
m.q = i
assert i.x.v.v.v.v.txt == "d"