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

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

k = A("k")
e = B("e")
h = B("h")
g = A("g")

k.y = h
k.o = g
e.r = h
h.r = e
g.y = e
g.o = k
assert k.y.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: A = None
        self.txt = txt

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

k = A("k")
e = B("e")
h = B("h")
g = A("g")

k.y = h
k.o = g
e.r = h
h.r = e
g.y = e
g.o = k
assert k.y.r.r.r.txt == "e"