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

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

d = A("d")
m = B("m")
i = B("i")
f = B("f")
g = A("g")
j = B("j")
h = B("h")
e = A("e")
b = A("b")

d.o = g
m.s = h
m.v = g
i.s = m
i.v = d
f.s = j
f.v = g
g.o = d
j.s = m
j.v = b
h.s = f
h.v = g
e.o = b
b.o = d
assert f.v.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.s: B = None
        self.v: A = None
        self.txt = txt

d = A("d")
m = B("m")
i = B("i")
f = B("f")
g = A("g")
j = B("j")
h = B("h")
e = A("e")
b = A("b")

d.o = g
m.s = h
m.v = g
i.s = m
i.v = d
f.s = j
f.v = g
g.o = d
j.s = m
j.v = b
h.s = f
h.v = g
e.o = b
b.o = d
assert f.v.o.o.o.o.txt == "g"