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

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

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

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

g = A("g")
f = B("f")
j = C("j")
e = D("e")

g.s = f
f.y = g
f.u = g
f.p = g
f.v = e
j.p = e
j.s = g
j.x = f
e.y = f
assert f.p.s.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

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

g = A("g")
f = B("f")
j = C("j")
e = D("e")

g.s = f
f.y = g
f.u = g
f.p = g
f.v = e
j.p = e
j.s = g
j.x = f
e.y = f
assert f.p.s.y.txt == "g"