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

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

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

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

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

j.w = i
j.r = n
g.p = n
i.t = g
n.p = j
assert i.t.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: D = None
        self.txt = txt

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

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

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

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

j.w = i
j.r = n
g.p = n
i.t = g
n.p = j
assert i.t.p.p.txt == "j"