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

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

a = A("a")
f = B("f")
i = B("i")
j = B("j")
l = A("l")
g = B("g")

a.w = l
f.x = g
f.o = i
i.x = g
i.o = f
j.x = f
j.o = i
l.w = a
g.x = j
g.o = f
assert f.x.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

a = A("a")
f = B("f")
i = B("i")
j = B("j")
l = A("l")
g = B("g")

a.w = l
f.x = g
f.o = i
i.x = g
i.o = f
j.x = f
j.o = i
l.w = a
g.x = j
g.o = f
assert f.x.o.o.o.o.txt == "i"