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

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

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

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

f = A("f")
c = B("c")
j = C("j")
a = D("a")

f.z = a
c.p = f
c.s = f
j.v = a
j.u = c
j.w = c
a.r = j
a.o = f
assert j.v.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
j = C("j")
a = D("a")

f.z = a
c.p = f
c.s = f
j.v = a
j.u = c
j.w = c
a.r = j
a.o = f
assert j.v.o.z.txt == "a"