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

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

b = A("b")
l = B("l")
h = B("h")
c = B("c")
m = A("m")
d = B("d")
g = A("g")

b.o = m
l.v = b
h.v = b
c.v = g
m.o = b
d.v = m
g.o = m
assert m.o.o.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

b = A("b")
l = B("l")
h = B("h")
c = B("c")
m = A("m")
d = B("d")
g = A("g")

b.o = m
l.v = b
h.v = b
c.v = g
m.o = b
d.v = m
g.o = m
assert m.o.o.o.o.o.o.o.txt == "b"