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

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

n = A("n")
g = B("g")
m = B("m")
l = A("l")
i = A("i")

n.x = g
n.z = g
g.t = l
g.y = m
m.t = n
m.y = g
l.x = g
l.z = m
i.x = m
i.z = m
assert i.z.t.x.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.z: B = None
        self.txt = txt

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

n = A("n")
g = B("g")
m = B("m")
l = A("l")
i = A("i")

n.x = g
n.z = g
g.t = l
g.y = m
m.t = n
m.y = g
l.x = g
l.z = m
i.x = m
i.z = m
assert i.z.t.x.y.t.txt == "n"