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

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

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

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

g = A("g")
j = B("j")
l = C("l")
e = D("e")

g.y = e
g.o = l
j.p = g
j.x = e
j.r = e
l.r = j
l.w = g
e.v = g
assert j.p.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.o: C = None
        self.txt = txt

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

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

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

g = A("g")
j = B("j")
l = C("l")
e = D("e")

g.y = e
g.o = l
j.p = g
j.x = e
j.r = e
l.r = j
l.w = g
e.v = g
assert j.p.y.v.txt == "g"