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

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

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

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

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

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

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

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

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

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

g.v = j
n.y = g
j.q = n
i.o = g
i.w = n
assert n.y.v.q.txt == "n"