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

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

a = A("a")
i = B("i")
j = B("j")
n = B("n")
d = B("d")
m = B("m")
g = A("g")

a.y = d
i.u = g
i.x = g
j.u = g
j.x = g
n.u = a
n.x = g
d.u = g
d.x = a
m.u = g
m.x = a
g.y = d
assert j.u.y.u.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

a = A("a")
i = B("i")
j = B("j")
n = B("n")
d = B("d")
m = B("m")
g = A("g")

a.y = d
i.u = g
i.x = g
j.u = g
j.x = g
n.u = a
n.x = g
d.u = g
d.x = a
m.u = g
m.x = a
g.y = d
assert j.u.y.u.y.x.txt == "a"