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

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

a = A("a")
i = B("i")
g = C("g")
d = D("d")

a.x = i
i.v = g
i.y = a
g.x = i
d.w = a
assert d.w.x.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

a = A("a")
i = B("i")
g = C("g")
d = D("d")

a.x = i
i.v = g
i.y = a
g.x = i
d.w = a
assert d.w.x.y.x.txt == "i"