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

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.u: D = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
n = C("n")
d = D("d")

g.y = n
i.t = g
i.u = d
n.q = g
n.t = g
n.r = d
n.o = i
d.o = g
d.w = g
d.y = n
assert g.y.q.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.u: D = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
n = C("n")
d = D("d")

g.y = n
i.t = g
i.u = d
n.q = g
n.t = g
n.r = d
n.o = i
d.o = g
d.w = g
d.y = n
assert g.y.q.y.o.txt == "i"