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

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

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

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

c = A("c")
l = B("l")
g = C("g")
m = D("m")
e = C("e")

c.r = e
l.u = e
l.v = m
g.x = m
m.r = g
m.q = g
e.x = m
assert g.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

c = A("c")
l = B("l")
g = C("g")
m = D("m")
e = C("e")

c.r = e
l.u = e
l.v = m
g.x = m
m.r = g
m.q = g
e.x = m
assert g.x.q.x.txt == "m"