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

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

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

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

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

i.p = l
h.v = l
l.y = h
l.x = c
l.r = i
c.t = l
c.r = h
assert c.t.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

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

i.p = l
h.v = l
l.y = h
l.x = c
l.r = i
c.t = l
c.r = h
assert c.t.x.t.txt == "l"