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

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

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

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

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

j.z = e
j.o = d
l.z = e
l.r = d
e.x = d
e.q = j
e.z = l
d.r = e
assert e.x.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: D = None
        self.txt = txt

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

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

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

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

j.z = e
j.o = d
l.z = e
l.r = d
e.x = d
e.q = j
e.z = l
d.r = e
assert e.x.r.x.r.txt == "e"