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

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

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

f = A("f")
b = B("b")
k = C("k")
g = B("g")

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

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

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

f = A("f")
b = B("b")
k = C("k")
g = B("g")

f.x = k
f.y = k
b.o = g
b.x = g
k.y = f
k.r = g
g.o = b
g.x = b
assert k.r.x.x.txt == "g"