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

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

j = A("j")
d = B("d")
h = B("h")
i = A("i")
b = B("b")
a = B("a")
g = A("g")

j.v = i
d.o = h
d.s = j
h.o = d
h.s = i
i.v = j
b.o = h
b.s = j
a.o = h
a.s = j
g.v = i
assert d.o.o.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

j = A("j")
d = B("d")
h = B("h")
i = A("i")
b = B("b")
a = B("a")
g = A("g")

j.v = i
d.o = h
d.s = j
h.o = d
h.s = i
i.v = j
b.o = h
b.s = j
a.o = h
a.s = j
g.v = i
assert d.o.o.s.v.txt == "i"