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

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

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

g = A("g")
l = B("l")
d = C("d")
c = C("c")

g.x = c
l.w = g
l.r = d
d.s = c
c.s = d
assert c.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
d = C("d")
c = C("c")

g.x = c
l.w = g
l.r = d
d.s = c
c.s = d
assert c.s.s.s.s.txt == "c"