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

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

d = A("d")
a = B("a")
e = B("e")
c = B("c")
k = B("k")
g = A("g")

d.s = g
a.z = e
a.o = d
e.z = a
e.o = g
c.z = e
c.o = g
k.z = e
k.o = d
g.s = d
assert e.o.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

d = A("d")
a = B("a")
e = B("e")
c = B("c")
k = B("k")
g = A("g")

d.s = g
a.z = e
a.o = d
e.z = a
e.o = g
c.z = e
c.o = g
k.z = e
k.o = d
g.s = d
assert e.o.s.s.txt == "g"