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

class B:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.x: C = None
        self.z: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: A = None
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

c.x = m
c.o = g
n.r = d
n.y = c
n.x = g
n.z = h
g.q = b
g.x = b
h.x = n
h.z = c
h.y = d
h.o = d
d.q = b
d.x = h
b.x = n
b.z = c
b.y = g
b.o = d
m.r = d
m.y = c
m.x = g
m.z = h
assert g.x.o.q.x.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.x: C = None
        self.z: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: A = None
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

c.x = m
c.o = g
n.r = d
n.y = c
n.x = g
n.z = h
g.q = b
g.x = b
h.x = n
h.z = c
h.y = d
h.o = d
d.q = b
d.x = h
b.x = n
b.z = c
b.y = g
b.o = d
m.r = d
m.y = c
m.x = g
m.z = h
assert g.x.o.q.x.y.o.txt == "g"