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

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

g = A("g")
k = B("k")
e = A("e")
l = A("l")
d = B("d")

g.o = k
g.x = l
k.x = d
e.o = k
e.x = l
l.o = k
l.x = g
d.x = k
assert e.o.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.x: A = None
        self.txt = txt

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

g = A("g")
k = B("k")
e = A("e")
l = A("l")
d = B("d")

g.o = k
g.x = l
k.x = d
e.o = k
e.x = l
l.o = k
l.x = g
d.x = k
assert e.o.x.x.x.x.txt == "k"