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

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

b.o = j
n.w = h
h.o = g
i.o = g
c.o = g
a.w = i
g.o = b
l.w = c
d.w = c
j.o = g
assert n.w.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

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

b.o = j
n.w = h
h.o = g
i.o = g
c.o = g
a.w = i
g.o = b
l.w = c
d.w = c
j.o = g
assert n.w.o.o.o.o.txt == "g"