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

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

a = A("a")
k = B("k")
g = A("g")
f = A("f")

a.o = g
a.r = f
k.x = g
g.o = f
g.r = f
f.o = g
f.r = a
assert g.o.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: A = None
        self.txt = txt

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

a = A("a")
k = B("k")
g = A("g")
f = A("f")

a.o = g
a.r = f
k.x = g
g.o = f
g.r = f
f.o = g
f.r = a
assert g.o.r.r.r.txt == "a"