class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: B = 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.v: B = None
        self.w: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
c = C("c")
h = D("h")

j.r = c
j.w = i
i.p = h
c.v = i
c.w = i
h.x = j
h.r = i
assert i.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: B = 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.v: B = None
        self.w: B = None
        self.txt = txt

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

j = A("j")
i = B("i")
c = C("c")
h = D("h")

j.r = c
j.w = i
i.p = h
c.v = i
c.w = i
h.x = j
h.r = i
assert i.p.r.p.r.txt == "i"