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

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

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

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

g = A("g")
n = B("n")
c = C("c")
h = D("h")

g.r = n
g.s = h
g.q = h
n.u = g
c.u = g
h.x = n
assert g.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: D = None
        self.q: D = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
c = C("c")
h = D("h")

g.r = n
g.s = h
g.q = h
n.u = g
c.u = g
h.x = n
assert g.r.u.r.txt == "n"