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

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

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

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

b = A("b")
g = B("g")
c = C("c")
f = D("f")

b.q = g
b.t = c
b.y = f
g.q = b
g.s = b
g.u = c
g.p = f
c.v = g
c.r = b
f.v = c
assert g.s.y.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.y: D = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
c = C("c")
f = D("f")

b.q = g
b.t = c
b.y = f
g.q = b
g.s = b
g.u = c
g.p = f
c.v = g
c.r = b
f.v = c
assert g.s.y.v.v.txt == "g"