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

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

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

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

m = A("m")
g = B("g")
n = C("n")
j = D("j")

m.y = g
g.q = j
g.v = j
g.y = n
n.t = g
j.x = n
j.u = g
j.o = m
assert j.o.y.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

m = A("m")
g = B("g")
n = C("n")
j = D("j")

m.y = g
g.q = j
g.v = j
g.y = n
n.t = g
j.x = n
j.u = g
j.o = m
assert j.o.y.v.u.txt == "g"