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

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

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

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

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

f.q = j
j.x = f
j.y = f
j.v = a
a.r = j
a.p = j
a.z = m
a.t = m
m.z = f
assert f.q.x.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

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

f.q = j
j.x = f
j.y = f
j.v = a
a.r = j
a.p = j
a.z = m
a.t = m
m.z = f
assert f.q.x.q.y.txt == "f"