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

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

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

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

j = A("j")
m = B("m")
g = C("g")
i = D("i")

j.p = m
j.s = i
j.x = g
m.o = i
m.x = j
m.w = g
g.r = j
i.x = g
assert j.x.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: D = None
        self.x: C = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
g = C("g")
i = D("i")

j.p = m
j.s = i
j.x = g
m.o = i
m.x = j
m.w = g
g.r = j
i.x = g
assert j.x.r.p.txt == "m"