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

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

f = A("f")
g = B("g")
h = B("h")
c = A("c")
l = B("l")
k = A("k")
d = B("d")

f.o = g
f.w = c
g.x = h
h.x = g
c.o = l
c.w = f
l.x = d
k.o = h
k.w = f
d.x = l
assert k.w.w.o.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.w: A = None
        self.txt = txt

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

f = A("f")
g = B("g")
h = B("h")
c = A("c")
l = B("l")
k = A("k")
d = B("d")

f.o = g
f.w = c
g.x = h
h.x = g
c.o = l
c.w = f
l.x = d
k.o = h
k.w = f
d.x = l
assert k.w.w.o.x.x.x.x.txt == "l"