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

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

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

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

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

j.r = e
c.w = f
c.s = f
c.x = e
f.s = j
f.p = j
e.s = c
e.o = c
assert e.s.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

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

j.r = e
c.w = f
c.s = f
c.x = e
f.s = j
f.p = j
e.s = c
e.o = c
assert e.s.x.o.txt == "c"