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

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

g = A("g")
m = B("m")
i = A("i")
n = B("n")
c = A("c")
h = B("h")
d = A("d")
f = B("f")

g.o = c
m.w = i
i.o = d
n.w = i
c.o = g
h.w = g
d.o = i
f.w = g
assert n.w.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.w: A = None
        self.txt = txt

g = A("g")
m = B("m")
i = A("i")
n = B("n")
c = A("c")
h = B("h")
d = A("d")
f = B("f")

g.o = c
m.w = i
i.o = d
n.w = i
c.o = g
h.w = g
d.o = i
f.w = g
assert n.w.o.o.o.o.o.o.txt == "i"