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

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

k = A("k")
g = B("g")
f = A("f")
l = B("l")

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

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

k = A("k")
g = B("g")
f = A("f")
l = B("l")

k.w = g
k.y = g
g.o = l
f.w = l
f.y = l
l.o = g
assert k.y.o.o.txt == "g"