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

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

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

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

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

f.u = d
a.s = g
a.q = i
a.o = d
g.s = i
g.t = f
d.y = g
i.s = g
i.q = a
i.o = d
assert d.y.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

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

f.u = d
a.s = g
a.q = i
a.o = d
g.s = i
g.t = f
d.y = g
i.s = g
i.q = a
i.o = d
assert d.y.s.s.txt == "g"