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

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

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

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

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

n.q = d
n.o = d
n.t = l
l.x = b
m.p = g
f.w = a
a.q = d
a.t = b
a.o = n
c.x = h
b.x = h
g.p = m
h.x = l
d.q = a
d.o = a
d.t = b
assert c.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: B = None
        self.o: A = None
        self.txt = txt

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

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

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

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

n.q = d
n.o = d
n.t = l
l.x = b
m.p = g
f.w = a
a.q = d
a.t = b
a.o = n
c.x = h
b.x = h
g.p = m
h.x = l
d.q = a
d.o = a
d.t = b
assert c.x.x.x.txt == "b"