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

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

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

n = A("n")
b = B("b")
i = C("i")
d = C("d")
f = A("f")

n.r = d
n.x = f
b.s = i
i.y = n
d.y = f
f.r = d
f.x = n
assert n.r.y.x.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.x: A = None
        self.txt = txt

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

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

n = A("n")
b = B("b")
i = C("i")
d = C("d")
f = A("f")

n.r = d
n.x = f
b.s = i
i.y = n
d.y = f
f.r = d
f.x = n
assert n.r.y.x.x.r.txt == "d"