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

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

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

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

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

a.y = i
g.v = c
g.q = c
g.r = a
c.v = i
c.t = g
i.v = c
assert a.y.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

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

a.y = i
g.v = c
g.q = c
g.r = a
c.v = i
c.t = g
i.v = c
assert a.y.v.v.txt == "i"