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

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

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

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

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

n.q = b
n.s = b
b.u = n
b.w = g
b.t = j
j.q = g
g.v = b
assert b.t.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

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

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

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

n.q = b
n.s = b
b.u = n
b.w = g
b.t = j
j.q = g
g.v = b
assert b.t.q.v.txt == "b"