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

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

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

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

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

f.t = g
g.w = a
g.u = a
g.v = f
g.y = d
d.r = a
a.t = f
assert d.r.t.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

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

f.t = g
g.w = a
g.u = a
g.v = f
g.y = d
d.r = a
a.t = f
assert d.r.t.t.w.txt == "a"