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

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

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

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

c = A("c")
d = B("d")
m = C("m")
g = D("g")

c.x = d
d.r = m
d.x = m
d.v = c
m.t = g
g.s = d
g.r = d
assert d.v.x.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
m = C("m")
g = D("g")

c.x = d
d.r = m
d.x = m
d.v = c
m.t = g
g.s = d
g.r = d
assert d.v.x.v.x.txt == "d"