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

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

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

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

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

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

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

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

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

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

c.y = m
c.u = g
m.p = c
m.s = f
f.y = c
f.t = c
f.q = g
g.u = c
assert m.p.y.s.q.txt == "g"