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

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

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

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

j = A("j")
m = B("m")
k = C("k")
e = D("e")

j.p = m
m.t = k
m.o = k
m.x = j
k.p = j
k.w = j
e.p = j
e.t = m
assert m.t.w.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
k = C("k")
e = D("e")

j.p = m
m.t = k
m.o = k
m.x = j
k.p = j
k.w = j
e.p = j
e.t = m
assert m.t.w.p.t.txt == "k"