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

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

a = A("a")
b = B("b")
e = A("e")
k = A("k")
j = B("j")
f = B("f")

a.o = k
b.y = j
e.o = a
k.o = e
j.y = f
f.y = j
assert a.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.y: B = None
        self.txt = txt

a = A("a")
b = B("b")
e = A("e")
k = A("k")
j = B("j")
f = B("f")

a.o = k
b.y = j
e.o = a
k.o = e
j.y = f
f.y = j
assert a.o.o.o.o.txt == "k"