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

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

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

d = A("d")
k = B("k")
e = C("e")
f = A("f")
b = C("b")

d.r = k
d.x = f
k.w = e
e.w = k
e.q = b
e.r = f
f.r = k
f.x = d
b.w = k
b.q = e
b.r = d
assert d.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.x: A = None
        self.txt = txt

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

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

d = A("d")
k = B("k")
e = C("e")
f = A("f")
b = C("b")

d.r = k
d.x = f
k.w = e
e.w = k
e.q = b
e.r = f
f.r = k
f.x = d
b.w = k
b.q = e
b.r = d
assert d.x.x.x.x.x.txt == "f"