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

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

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

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

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

c.q = g
j.z = a
g.o = j
g.z = j
g.p = j
a.z = c
assert g.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

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

c.q = g
j.z = a
g.o = j
g.z = j
g.p = j
a.z = c
assert g.z.z.z.txt == "c"