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

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

g = A("g")
e = B("e")
j = A("j")
l = B("l")
h = B("h")
c = B("c")
n = B("n")
k = B("k")

g.o = j
e.y = j
j.o = g
l.y = j
h.y = g
c.y = g
n.y = g
k.y = g
assert h.y.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: A = None
        self.txt = txt

g = A("g")
e = B("e")
j = A("j")
l = B("l")
h = B("h")
c = B("c")
n = B("n")
k = B("k")

g.o = j
e.y = j
j.o = g
l.y = j
h.y = g
c.y = g
n.y = g
k.y = g
assert h.y.o.o.txt == "g"